dashboard
repositories
activity
search
login
common
/
securis
summary
reflog
commits
tree
compare
forks
blame
|
history
|
raw
|
HEAD
#396 feature - Refactoring error management
Roberto Sánchez
2014-01-21
b83a0ba903b56562751963c106b4c20352c26087
[common/securis.git]
/
securis
/
src
/
main
/
java
/
net
/
curisit
/
securis
/
DefaultExceptionHandler.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package net.curisit.securis;
import javax.ws.rs.ForbiddenException;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;
@Provider
public class DefaultExceptionHandler implements ExceptionMapper<Exception> {
public static final String ERROR_MESSAGE_HEADER = "X-SECURIS-ERROR";
public DefaultExceptionHandler() {
MainApp.log.info("Creating DefaultExceptionHandler ");
}
@Override
public Response toResponse(Exception e) {
// log.info("Creating DefaultExceptionHandler ");
// e.printStackTrace();
if (e instanceof ForbiddenException)
return Response.status(Status.UNAUTHORIZED).header(ERROR_MESSAGE_HEADER, "Unathorized access to the application").type(MediaType.APPLICATION_JSON).build();
return Response.serverError().header(ERROR_MESSAGE_HEADER, "Unexpected error: " + e.toString()).type(MediaType.APPLICATION_JSON).build();
}
}