@Getter
@Builder
@AllArgsConstructor(access = AccessLevel.PRIVATE)
public class ErrorResponse {
private final String code;
private final String codeName;
private final String message;
private final LocalDateTime time = LocalDateTime.now();
private final String transactionId = MDC.get("transactionId");
private final List<FieldError> errors;
public static ErrorResponse of(final ErrorCode errorCode, final List<FieldError> errors) {
return ErrorResponse.builder()
.code(errorCode.getCode())
.codeName(errorCode.name())
.message(errorCode.getReason())
.errors(errors)
.build();
}
public static ErrorResponse of(final ErrorCode errorCode) {
return ErrorResponse.builder()
.code(errorCode.getCode())
.codeName(errorCode.name())
.message(errorCode.getReason())
.errors(new ArrayList<>()) // errors 가 없다면 초기 값을 넣어줌.
.build();
}
}