Unverified Commit d33cf8bb authored by Féry Mathieu (Mathius)'s avatar Féry Mathieu (Mathius)
Browse files

feat(error): Improve logging of RuntineException catched

parent a2bd7165
...@@ -30,9 +30,30 @@ public class OwnErrorController implements ErrorController { ...@@ -30,9 +30,30 @@ public class OwnErrorController implements ErrorController {
return makeResponse(exception); return makeResponse(exception);
} }
public String exceptionLog(Throwable throwable) {
return exceptionLog(throwable, "");
}
public String exceptionLog(Throwable throwable, String msg) {
msg = String.format("%s%s has occured with message :%n%s%nStacktrace related:%s", msg,
throwable.getClass().getName(), throwable.getMessage(), stackTraceLog(throwable.getStackTrace()));
if (throwable.getCause() != null)
msg = exceptionLog(throwable.getCause(), String.format("%s%nWith following cause :%n", msg));
return msg;
}
public String stackTraceLog(StackTraceElement[] stackTraceElements) {
String msg = "";
for (StackTraceElement element : stackTraceElements)
msg = String.format("%s%n\t%s.%s(%s:%s)", msg, element.getClassName(), element.getMethodName(),
element.getFileName(), element.getLineNumber());
return msg;
}
@ExceptionHandler(RuntimeException.class) @ExceptionHandler(RuntimeException.class)
public ResponseEntity<ResponseError> handleError(@NonNull RuntimeException exception) { public ResponseEntity<ResponseError> handleError(@NonNull RuntimeException exception) {
logger.error(exception.getMessage()); logger.error(exceptionLog(exception));
return makeResponse(new ResponseError("Internal Error occured", HttpStatus.INTERNAL_SERVER_ERROR)); return makeResponse(new ResponseError("Internal Error occured", HttpStatus.INTERNAL_SERVER_ERROR));
} }
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment