Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @ControllerAdvice
- @Order(Ordered.LOWEST_PRECEDENCE)
- class UnknownExceptionHandler extends ResponseEntityExceptionHandler {
- @Value("${hrevolution.development}")
- private Boolean isDevelopment;
- @ExceptionHandler(Exception.class)
- ResponseEntity<BusinessError<?>> handleException(Exception ex) {
- String message = null;
- if (isDevelopment) {
- ex.printStackTrace();
- message = ex.getMessage();
- }
- return new ResponseEntity<>(
- new BusinessError<>(
- BusinessErrorKey.ERROR,
- message,
- null
- ),
- HttpStatus.BAD_REQUEST
- );
- }
- }
- @Getter
- @ToString
- public class BusinessError<T> {
- private final BusinessErrorKey key;
- private final String details;
- private final T payload;
- public BusinessError(BusinessErrorKey key) {
- this.key = key;
- this.details = null;
- this.payload = null;
- }
- public BusinessError(BusinessErrorKey key, T payload) {
- this.key = key;
- this.details = null;
- this.payload = payload;
- }
- public BusinessError(BusinessErrorKey key, String details, T payload) {
- this.key = key;
- this.details = details;
- this.payload = payload;
- }
- }
- public enum BusinessErrorKey {
- ERROR,
- NOT_FOUND,
- FORM_VALIDATION_ERROR,
- CANDIDATE_ALREADY_PART_OF_AGENCY,
- CANDIDATE_ALREADY_IN_PROGRESS_WITH_AN_AGENCY,
- CANDIDATE_NOT_IN_PROGRESS_WITH_AGENCY,
- NOT_ENOUGH_CREDITS,
- ALREADY_MATCHED,
- INVALID_MATCH,
- CAN_NOT_ADD_INTEREST_IN_YOUR_OWN_CANDIDATE,
- MATCH_NOT_EXISTING,
- ALREADY_VALIDATED,
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement