Frachtwerk / essencium-backend

Essencium Backend is a software library built on top of Spring Boot that allows developers to quickly get started on new software projects. Essencium provides, for example, a fully implemented role-rights concept as well as various field-tested solutions for access management and authentication.
GNU Lesser General Public License v3.0
15 stars 3 forks source link

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

Open cholakov11 opened 3 weeks ago

cholakov11 commented 3 weeks ago

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

sonarcloud[bot] commented 3 weeks ago

Quality Gate Passed Quality Gate passed

Issues
3 New issues
0 Accepted issues

Measures
0 Security Hotspots
100.0% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarCloud

JelmenGuhlke commented 1 week ago

@cholakov11 can we close this PR in favor of https://github.com/Frachtwerk/essencium-backend/pull/606 ?