-
Notifications
You must be signed in to change notification settings - Fork 22
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
Unify error responses #716
Conversation
IMHO it is a horrible approach... Probably using exception for flow control is a standard practice in micronaut but it does not change it is a horrible: an exception is thrown somewhere, no matter how deep it is thrown and then there is a magic |
This is how it works on Micronaut, as well as on Spring Boot. It allows framework users to focus more on business logic and not to focus on error handling and other supporting features. IMHO In this specific case it is ok to throw an exception from the Service layer, since the client of the service is trying to use it in unexpected manner. |
I know that both springBoot and micronaut allows one to create The concept of exception handlers is ok, if your outer layer catches true exceptions but the cases like: session in invalid state or validation error are not exceptions - they are just a regular, easy-to-predict cases, not sth like connection got broken, DB is down or whatever...
Fully disagree. Of course you can build protocol that forces one to first "check session state" before submitting a statement but how would you enforce this protocol. What would happen if in a time gap between checking if session is in valid state and statement submission, session become invalid ? |
Not only that - It has many handlers pre-built. For example Spring Boot has a handler for http client exceptions, Validation exceptions (hibernate validator, micronaut validator, other validators throws exception if request payload is not valid), etc... While your comments regarding Exception usage for flow control makes sense, despite I do not fully agree with it in this specific case, I do not want to have multiple converged flows for error handling:
So either we need to disable these framework features, and go with the new Result - Response mapping approach or go with the framework. |
The fact that spring boot or micronaut does something it does not mean ( out-of-box ) it is a valid solution... Again, if we were in kotlin/scala/typescript/haskell a standard way of returning multiple possible outputs from method (in this case a service) it by using algebraic data types - as I described in #710 My point is that by using "these weird mappers" you have full (and local control) how to map service output to httpresponse and everything is very explicit. if it happens that there is a lot of commonality between mappers you can solve it using regular software engineering practices.
Input Payload Validation is (at least in spring boot) handled as exception, but one does not need to do it that way. BTW do you think validation is part of a logic or not? If it is a part of logic than it shall be part of service, not part of controller...
Look how inconsistent it is: some HTTP responses are defined via return types, like using TLDR: if you look long-jumps and control flow by exceptions, go for it |
Had to replace custom response building logics from session status validation with thrown exception, to route it through the same flow as other request errors are routed.
in case of not found error:
In case of invalid session state:
in case of validation error:
@Minutis
/cc @jmilkiewicz