3 ms·
Always avoid throwing custom exceptions. Example: ResponseStatusException in the spring framework. You can at any point throw ResponseStatusException + http st
by Traubenfuchs 4y ago
Always avoid throwing custom exceptions. Example: ResponseStatusException in the spring framework.
You can at any point throw ResponseStatusException + http status code + optional message, for example
throw new ResponseStatusException(BAD_REQUEST, "resource must be in status EDITABLE, but is in status " + status);
You can also define an error handler for this exception type to convert it in whatever error response format you desire.
Writing custom exceptions for everything is the definition of overengineering, falls into the YAGNI trap and means kicking KISS with your feet.
- deleted 4y ago[deleted]