Skip to content

fix: 390-handling-property-reference-exception#589

Open
cholakov11 wants to merge 3 commits into
mainfrom
390-handling-property-reference-exception
Open

fix: 390-handling-property-reference-exception#589
cholakov11 wants to merge 3 commits into
mainfrom
390-handling-property-reference-exception

Conversation

@cholakov11

Copy link
Copy Markdown
Contributor

Implemented an exception handler to handle PropertyReferenceException caused by an invalid value in the sort query parameter. Previous behaviour resulted in an Internal Error 500 response with a full trace of the exception. Now the API will respond with the error format used for reporting other errors (e.g Unauthorized) and omits the exception trace thus resulting in a more clear and user-friendly response.

Note: Invalid values for the other query parameters - page and size, are handled with an OK response from the server and a json containing results for the request with the invalid values substituted by default valid. In order to keep the invalid query handling consistent, the initial idea was to filter the sort parameter for invalid values and in case of such present to return an unsorted response.
This could be achieved with reflection and matching sort parameter with defined fields of the java object. However since the Pageable interface is used to transmit the query parameters, the Pageable object annot be edited in a pre-processing function to remove invalid sort values and pass a new Pageable with only valid values and thus avoid the PropertyReferenceException. The only option is to construct a SimplePageRequest which implements Pageable with the edited sort values and pass it on. This however breaks the Dependency Inversion principle and should be avoided.
Therefore, at this point no solution will be implemented to handles the sort parameter like the other two and we will resolve to an ExceptionHandler.

fixes #390

@sonarqubecloud

Copy link
Copy Markdown

@cholakov11 cholakov11 changed the title 390-handling-property-reference-exception fix: 390-handling-property-reference-exception Sep 16, 2024
@JelmenGuhlke

Copy link
Copy Markdown
Contributor

@cholakov11 can we close this PR in favor of #606 ?

@pwannenmacher pwannenmacher left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CHANGELOG.md conflicts with main. Some unwanted changes seem to have occurred there (probably due to automatic formatting). Please rebase and remove all unwanted changes to CHANGELOG.md.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Wrong values in SORT BY lead to error status 500

3 participants