Advertisement
marcgruita

bucian

May 8th, 2024 (edited)
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. @ControllerAdvice
  2. @Order(Ordered.LOWEST_PRECEDENCE)
  3. class UnknownExceptionHandler extends ResponseEntityExceptionHandler {
  4.  
  5. @Value("${hrevolution.development}")
  6. private Boolean isDevelopment;
  7.  
  8. @ExceptionHandler(Exception.class)
  9. ResponseEntity<BusinessError<?>> handleException(Exception ex) {
  10. String message = null;
  11. if (isDevelopment) {
  12. ex.printStackTrace();
  13. message = ex.getMessage();
  14. }
  15.  
  16. return new ResponseEntity<>(
  17. new BusinessError<>(
  18. BusinessErrorKey.ERROR,
  19. message,
  20. null
  21. ),
  22. HttpStatus.BAD_REQUEST
  23. );
  24. }
  25.  
  26. }
  27.  
  28.  
  29.  
  30.  
  31. @Getter
  32. @ToString
  33. public class BusinessError<T> {
  34.  
  35. private final BusinessErrorKey key;
  36.  
  37. private final String details;
  38.  
  39. private final T payload;
  40.  
  41. public BusinessError(BusinessErrorKey key) {
  42. this.key = key;
  43. this.details = null;
  44. this.payload = null;
  45. }
  46.  
  47. public BusinessError(BusinessErrorKey key, T payload) {
  48. this.key = key;
  49. this.details = null;
  50. this.payload = payload;
  51. }
  52.  
  53. public BusinessError(BusinessErrorKey key, String details, T payload) {
  54. this.key = key;
  55. this.details = details;
  56. this.payload = payload;
  57. }
  58.  
  59. }
  60.  
  61.  
  62.  
  63. public enum BusinessErrorKey {
  64. ERROR,
  65. NOT_FOUND,
  66. FORM_VALIDATION_ERROR,
  67. CANDIDATE_ALREADY_PART_OF_AGENCY,
  68. CANDIDATE_ALREADY_IN_PROGRESS_WITH_AN_AGENCY,
  69. CANDIDATE_NOT_IN_PROGRESS_WITH_AGENCY,
  70. NOT_ENOUGH_CREDITS,
  71. ALREADY_MATCHED,
  72. INVALID_MATCH,
  73. CAN_NOT_ADD_INTEREST_IN_YOUR_OWN_CANDIDATE,
  74. MATCH_NOT_EXISTING,
  75. ALREADY_VALIDATED,
  76. }
  77.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement