Created
January 26, 2017 02:44
-
-
Save loganlinn/3789d6fa8fc10726072c2d2020534ad2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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