Skip to content

Instantly share code, notes, and snippets.

@loganlinn
Created January 26, 2017 02:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save loganlinn/3789d6fa8fc10726072c2d2020534ad2 to your computer and use it in GitHub Desktop.
Save loganlinn/3789d6fa8fc10726072c2d2020534ad2 to your computer and use it in GitHub Desktop.
import org.apache.commons.lang.exception.ExceptionUtils;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;
import java.util.StringJoiner;
/**
* Catch-all exception mapper that creates response with message and stack trace.
*/
@Provider
public class DebugExceptionMapper implements ExceptionMapper<Exception> {
@Override
public Response toResponse(Exception e) {
final StringJoiner body = new StringJoiner("\n\n");
body.add("==== Uncaught Exception ====");
body.add("Message: " + e.getMessage());
body.add("Stack: \n" + ExceptionUtils.getStackTrace(e));
return Response.status(500)
.entity(body.toString())
.type(MediaType.TEXT_PLAIN_TYPE)
.build();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment