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

Custom exceptions instead of exception handling #83

Open
h1alexbel opened this issue Mar 12, 2024 · 2 comments
Open

Custom exceptions instead of exception handling #83

h1alexbel opened this issue Mar 12, 2024 · 2 comments

Comments

@h1alexbel
Copy link
Collaborator

h1alexbel commented Mar 12, 2024

now we doing something like this:

throw new ResourceAlreadyExistsException(...);

and we do support exception handling via Spring Exception Handlers:

@ExceptionHandler(ResponseStatusException.class)
public ResponseEntity<byte[]> handle(
final ResponseStatusException exception
) {
return new Logged(
exception,
new RestError(
exception.getMessage(),
HttpStatus.valueOf(exception.getStatusCode().value())
)
).value();
}

We actually can get rid of this by making all our custom exceptions extend HttpStatusException. After this all of them will be handled by Spring

@hizmailovich wdyt?

@dukris
Copy link
Collaborator

dukris commented Mar 12, 2024

But for now our custom exceptions are already inherited from ResponseStatusException. Why would it be better to replace it with HttpStatusException? We will still need to handle it in ControllerAdvice...

@h1alexbel
Copy link
Collaborator Author

@hizmailovich If we do inherit HttpStatusException then we can remove Exception Handling inside ControllerAdvice

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

No branches or pull requests

2 participants