spring-projects / spring-projects/spring-data-rest

Sending multiple links to a *-to-one association responds with 500 Internal Server Error

Open
#2,395 1 comment 3 reactions 1 assignee View on GitHub

@odrotbohm is already working on this.

Since Jul 15, 2024.

status: waiting-for-triage
Dominant language
Java
Stars
958
Forks
568
PR merge metrics
No merged PRs in 30d

Description

When sending multiple links to a one-to-one or many-to-one association, the server responds with 500 Internal server error due to the RepositoryPropertyReferenceController throwing an IllegalArgumentException (message: "Must send only 1 link to update a property reference that isn't a List or a Map."). Since a general IllegalArgumentException is thrown, this results in a HTTP 500 error from https://github.com/spring-projects/spring-data-rest/blob/aaadc344ab1bef4ed98cb0dbf6ca8ebd7c9262ff/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/RepositoryRestExceptionHandler.java#L88-L99.
Typically, the response for an error triggered by user input would be in the 4xx range, e.g. 400 Bad Request.
If a more specific exception was thrown, it could be handled by the ExceptionHandler to return a more correct HTTP error, and developers that integrate spring-data-rest can supply their own @ExceptionHandler to handle this error as well.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.