Created
December 21, 2020 12:55
-
-
Save anny0739/584b41120c01bfd0e8b5f911c4b10465 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ErrorResponseResolver { | |
public <T extends Throwable> void test(T t) | |
throws InvocationTargetException, IllegalAccessException { | |
Method[] methods = getClass().getDeclaredMethods(); | |
for (Method method : methods) { | |
String clazzName = t.getClass().getName(); | |
if (clazzName.equals(method.getParameterTypes()[0].getName())) { | |
method.invoke(t, t); // 실행한다! | |
} | |
} | |
} | |
public static ErrorAttribute resolveToResponse(FeignException exception) { | |
final ErrorCode errorCode = ErrorCode.BAD_REQUEST; | |
return new ErrorAttribute(errorCode.getHttpStatus(), JsonUtils | |
.convertBytes(new Errors<>(errorCode.getCode(), exception.getMessage()))); | |
} | |
public static ErrorAttribute resolveToResponse(ResponseStatusException exception) { | |
final ErrorCode errorCode = ErrorCode.BAD_REQUEST; | |
return new ErrorAttribute(errorCode.getHttpStatus(), JsonUtils | |
.convertBytes(new Errors<>(errorCode.getCode(), exception.getReason()))); | |
} | |
public static ErrorAttribute resolveToResponse(GatewayException exception) { | |
final ErrorCode errorCode = ErrorCode.BAD_REQUEST; | |
return new ErrorAttribute(errorCode.getHttpStatus(), JsonUtils | |
.convertBytes(new Errors<>(errorCode.getCode(), exception.getMessage()))); | |
} | |
// TODO : CustomRunTimeException Define (Include ErrorCode) | |
@AllArgsConstructor | |
@Getter | |
public static class ErrorAttribute { | |
private final HttpStatus status; | |
private final byte[] errorMessageBytes; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment