Skip to content

Instantly share code, notes, and snippets.

@anny0739
Created December 21, 2020 12:55
Show Gist options
  • Save anny0739/584b41120c01bfd0e8b5f911c4b10465 to your computer and use it in GitHub Desktop.
Save anny0739/584b41120c01bfd0e8b5f911c4b10465 to your computer and use it in GitHub Desktop.
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