Skip to content

Commit

Permalink
errors fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ttrubinov committed Jun 24, 2024
1 parent 537c288 commit 93e2437
Showing 1 changed file with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,21 @@ private void handle(HttpServletResponse response, ServerException serverExceptio
}
}

@ExceptionHandler(NullPointerException.class)
private void handle(HttpServletResponse response, NullPointerException nullPointerException) {
response.setStatus(500);
response.addHeader("Content-Type", MediaType.APPLICATION_JSON_VALUE);
ObjectMapper mapper = new ObjectMapper();
try (BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(response.getOutputStream()))) {
bw.write(mapper.writeValueAsString(
nullPointerException.getMessage() + " " +
nullPointerException.getCause() + " " +
Arrays.toString(nullPointerException.getStackTrace())
));
} catch (IOException e) {
// log.error(e.getMessage());
throw new RuntimeException(e);
}
}

}

0 comments on commit 93e2437

Please sign in to comment.