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

Exception mapping #24

Open
wants to merge 19 commits into
base: master
Choose a base branch
from

Conversation

GuentherJulian
Copy link
Contributor

@GuentherJulian GuentherJulian commented Oct 6, 2021

Added RestServiceExceptionFacade as described in issue #12 for exception handling. Business exceptions are thrown through ApplicationBusinessException and return status 400 (bad request). Other runtime exceptions will result in a response with status 500 (internal server error).
Also did some refactoring of the rest service and the database migration script.

@GuentherJulian GuentherJulian self-assigned this Oct 6, 2021
@GuentherJulian GuentherJulian linked an issue Oct 6, 2021 that may be closed by this pull request
Copy link
Contributor

@hohwille hohwille left a comment

Choose a reason for hiding this comment

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

@GuentherJulian thanks for this PR. 👍
By some accident we got two PRs for the same story (see #25).
After both reviews this PR is closer to what Malte, Matus and I had in mind.
Can you please have a look at the review feedback and start rework/discussion.

Comment on lines 35 to 36
}
if (exception instanceof WebApplicationException) {
Copy link
Contributor

Choose a reason for hiding this comment

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

else?

also we should add support for JAX-RS Exceptions (that we have been lacking in devon4j) with e.g. NotFoundException procuding 404.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The Quarkus RESTEasy extension provides a mapper for NotFoundException out of the box, that produces a 404 response (https://github.com/quarkusio/quarkus/blob/main/extensions/resteasy-classic/resteasy/runtime/src/main/java/io/quarkus/resteasy/runtime/NotFoundExceptionMapper.java).
Should we anyway implement and use an own mapper for it?

Copy link
Contributor

Choose a reason for hiding this comment

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

If that already plays together with out exception mapper, it is fully sufficient. But then you could add a nice inline comment to the code giving this valuable information including that link so people can easily understand what is going on. I also was not aware of that so thanks for making this clear.

Copy link
Contributor

Choose a reason for hiding this comment

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

But comming back to my original concern:
How about permission denied? How about validation failures (from BV)?
We do not want to report this as 500 (internal server error)!
This is IMHO only complete if we have all these cases covered.
Ideally we even add a JUnit that is testing all these scenarios to make them transparent and to document our features and behaviour.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since the Quarkus ExceptionMapper implementations do not return any further information (only status code) I decided to create own implementations. So now we have exception mapper for NotFoundException, UnauthorizedException and ValidationException + our ApplicationBusinessException. Other exceptions are handled as WebApplicationException or as general Exception with status 500
@hohwille is this what you had in mind?

src/main/resources/db/migration/V001__Create_schema.sql Outdated Show resolved Hide resolved
@GuentherJulian
Copy link
Contributor Author

@hohwille thanks for your review comments. I have changed some parts accordingly. Can you please take again a look and check my comments?

Copy link
Contributor

@hohwille hohwille left a comment

Choose a reason for hiding this comment

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

Sorry, if I am picky and this PR is taking long to get merged.
However, I still have review feedback that should be addressed.

@maybeec
Copy link
Member

maybeec commented Dec 27, 2021

@GuentherJulian please check for the conflicts. thanks

# Conflicts:
#	src/main/java/com/devonfw/quarkus/general/rest/json/CustomObjectMapper.java
#	src/main/java/com/devonfw/quarkus/general/rest/json/PageSerializer.java
#	src/main/java/com/devonfw/quarkus/productmanagement/logic/UcFindProductImpl.java
#	src/main/java/com/devonfw/quarkus/productmanagement/logic/UcManageProduct.java
#	src/main/java/com/devonfw/quarkus/productmanagement/logic/UcManageProductImpl.java
#	src/main/java/com/devonfw/quarkus/productmanagement/rest/v1/ProductRestService.java
#	src/main/java/com/devonfw/quarkus/productmanagement/rest/v1/model/NewProductDto.java
#	src/main/resources/db/migration/V001__Create_schema.sql
#	src/main/resources/db/migration/V002__Master_data.sql
#	src/test/java/com/devonfw/demoquarkus/rest/v1/ProductRestServiceTest.java
@GuentherJulian
Copy link
Contributor Author

@GuentherJulian please check for the conflicts. thanks

@maybeec Conflicts resolved.

@maybeec
Copy link
Member

maybeec commented Dec 28, 2021

@hohwille ,waiting for your approval

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

Successfully merging this pull request may close these issues.

Extend sample app with RestExceptionFacade
3 participants