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

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

Fetching unknown profile returns 500 Internal Server Error #2480

AElmecker opened this issue May 14, 2025 · 1 comment
Labels
status: waiting-for-triage An issue we've not yet triaged

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 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: waiting-for-triage An issue we've not yet triaged
Projects
None yet
Development

No branches or pull requests

2 participants