Skip to content

Fetching unknown profile returns 500 Internal Server Error #2480

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
AElmecker opened this issue May 14, 2025 · 1 comment
Closed

Fetching unknown profile returns 500 Internal Server Error #2480

AElmecker opened this issue May 14, 2025 · 1 comment
Assignees
Labels
type: bug A general bug

Comments

@AElmecker
Copy link

AElmecker commented May 14, 2025

Observed Behavior

Fetching the profile for an unknown repository called foo:

GET http://localhost:8080/profile/foo

yields a 500 Internal Server Error with following response:

{
  "cause": null,
  "message": "Could not resolve repository metadata for foo."
}

The culprit seems to
be org.springframework.data.rest.webmvc.config.ResourceMetadataHandlerMethodArgumentResolver
throwing an IllegalArgumentException when it is not able to resolve the repository.

Expected Behavior

A 404 Not Found is returned like

{
  "timestamp": "2025-05-14T19:51:01.935+00:00",
  "status": 404,
  "error": "Not Found",
  "path": "/profile/foo"
}

Steps To Reproduce

I created a small reproducer with can be checked out in this repository, the readme there also contains a similar description as this issue.

  1. Start application
  2. Fetch profile for unknown repository
    curl -X GET --location "http://localhost:8080/profile/foo" -H "Accept: application/json"
  3. Retrieve 500 Internal Server Error

Spring Initializr Setup

  • Project: Gradle - Kotlin
  • Language: Java
  • Spring Boot: 3.4.5
  • Packaging: Jar
  • Java: 21
  • Dependencies
    • Spring Data JPA
    • Rest Repositories
    • H2 Database

Similar/Related issues

Some issue I already found that sounds similar is #2014, but that conversation came to an halt.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label May 14, 2025
@AElmecker
Copy link
Author

For anyone wondering how I workaround in the meantime:

@ControllerAdvice
public class PersistenceControllerAdvice {

	@ExceptionHandler(IllegalArgumentException.class)
	public ProblemDetail handleIllegalArgumentException(HttpServletRequest request, IllegalArgumentException ex) {
		if (ex.getMessage() != null && ex.getMessage().contains("Could not resolve repository metadata for")) {
			String uri = stripLeadingSlash(request.getRequestURI());
			return ProblemDetail.forStatusAndDetail(HttpStatus.NOT_FOUND, "No static resource " + uri + ".");
		} else {
			throw ex;
		}
	}

	private static String stripLeadingSlash(String path) {
		if (path.startsWith("/")) {
			return path.substring(1);
		} else {
			return path;
		}
	}
}

Improvements/Suggestions to the workaround appreciated as well :)

@mp911de mp911de added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels May 19, 2025
@mp911de mp911de assigned mp911de and odrotbohm and unassigned mp911de May 19, 2025
odrotbohm added a commit that referenced this issue May 20, 2025
… Found.

We now produce an HttpClientErrorException if ResourceMetadataHandlerMethodArgumentResolver fails for find metadata for a parsed repository key so that it automatically results in a 404 Not Found status code over a previous 500 Internal Server Error.

Fixes GH-2480
odrotbohm added a commit that referenced this issue May 20, 2025
… Found.

We now produce an HttpClientErrorException if ResourceMetadataHandlerMethodArgumentResolver fails for find metadata for a parsed repository key so that it automatically results in a 404 Not Found status code over a previous 500 Internal Server Error.

Fixes GH-2480
odrotbohm added a commit that referenced this issue May 20, 2025
… Found.

We now produce an HttpClientErrorException if ResourceMetadataHandlerMethodArgumentResolver fails for find metadata for a parsed repository key so that it automatically results in a 404 Not Found status code over a previous 500 Internal Server Error.

Fixes GH-2480
@odrotbohm odrotbohm added this to the 4.3.13 (2024.0.13) milestone May 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

4 participants