Skip to content

Commit

Permalink
Merge pull request #8 from telicent-oss/unhandled-stack-traces
Browse files Browse the repository at this point in the history
FallbackExceptionMapper logs stack traces (CORE-288)
  • Loading branch information
rvesse authored Jun 17, 2024
2 parents d0af1e8 + c6654a1 commit 8fad9c6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Change Log

# 0.20.1

- JAX-RS Base Server Improvements:
- `FallbackExceptionMapper` explicitly logs the stack trace for otherwise unhandled exceptions to aid in diagnosis
of the underlying issue

# 0.20.0

- Build improvements:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,17 @@
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.ext.ExceptionMapper;
import jakarta.ws.rs.ext.Provider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Maps otherwise unhandled errors into RFC 7807 Problem responses
*/
@Provider
public class FallbackExceptionMapper implements ExceptionMapper<Exception> {

private static final Logger LOGGER = LoggerFactory.getLogger(FallbackExceptionMapper.class);

private String buildDetail(Throwable e) {
StringBuilder builder = new StringBuilder();
while (e != null) {
Expand Down Expand Up @@ -55,6 +59,9 @@ public Response toResponse(Exception exception) {
//@formatter:on
}

// Explicitly log the error with its stack trace for diagnostic purposes
LOGGER.error("Unhandled exception, see stack trace for more detail:", exception);

// For any other error just translate into a 500 Internal Server Error
//@formatter:off
return new Problem("InternalServerError",
Expand Down

0 comments on commit 8fad9c6

Please # to comment.