Skip to content
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

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

Open
NielsCW opened this issue Jul 9, 2024 · 0 comments
Assignees
Labels
status: waiting-for-triage An issue we've not yet triaged

Comments

@NielsCW
Copy link

NielsCW commented Jul 9, 2024

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

/**
* Handle failures commonly thrown from code tries to read incoming data and convert or cast it to the right type by
* returning {@code 500 Internal Server Error} and the thrown exception marshalled into JSON.
*
* @param o_O the exception to handle.
* @return
*/
@ExceptionHandler({ InvocationTargetException.class, IllegalArgumentException.class, ClassCastException.class,
ConversionFailedException.class, NullPointerException.class })
ResponseEntity<ExceptionMessage> handleMiscFailures(Exception o_O) {
return errorResponse(HttpStatus.INTERNAL_SERVER_ERROR, new HttpHeaders(), o_O);
.
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.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jul 9, 2024
@NielsCW NielsCW changed the title Sending multiple links to a *-to-one association should respond with 400 Bad request Sending multiple links to a *-to-one association responds with 500 Internal Server Error Jul 10, 2024
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

3 participants