ErrorResponse.java 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package com.its.op.exception;
  2. import lombok.Builder;
  3. import lombok.Getter;
  4. import java.time.LocalDateTime;
  5. import java.util.ArrayList;
  6. import java.util.List;
  7. @Getter
  8. public class ErrorResponse {
  9. private LocalDateTime timestamp;
  10. private final int status;
  11. private String title;
  12. private final String message;
  13. private List<String> errors;
  14. @Builder
  15. public ErrorResponse(LocalDateTime timestamp, int status, String title, String message, List<String> errors) {
  16. this.timestamp = timestamp;
  17. this.status = status;
  18. this.title = title;
  19. this.message = message;
  20. this.errors = errors;//initErrors(errors);
  21. }
  22. private List<FieldError> initErrors(List<FieldError> errors) {
  23. return (errors == null) ? new ArrayList<>() : errors;
  24. }
  25. /*
  26. public static ErrorResponse buildError(ErrorCode errorCode) {
  27. return ErrorResponse.builder()
  28. .code(errorCode.getCode())
  29. .message(errorCode.getMessage())
  30. .build();
  31. }*/
  32. @Getter
  33. public static class FieldError {
  34. private final String field;
  35. private final String value;
  36. private final String reason;
  37. @Builder
  38. public FieldError(String field, String value, String reason) {
  39. this.field = field;
  40. this.value = value;
  41. this.reason = reason;
  42. }
  43. }
  44. }