rsanchez
2014-09-25 b77838d1005c45740968816c70088dff2ad655d3
securis/src/main/java/net/curisit/securis/DefaultExceptionHandler.java
....@@ -11,6 +11,7 @@
1111 import javax.ws.rs.ext.Provider;
1212
1313 import net.curisit.securis.services.exception.SeCurisServiceException;
14
+import net.curisit.securis.services.exception.SeCurisServiceException.ErrorCodes;
1415
1516 import org.apache.logging.log4j.LogManager;
1617 import org.apache.logging.log4j.Logger;
....@@ -19,7 +20,9 @@
1920 public class DefaultExceptionHandler implements ExceptionMapper<Exception> {
2021 private static final Logger LOG = LogManager.getLogger(DefaultExceptionHandler.class);
2122
22
- public static final String ERROR_MESSAGE_HEADER = "X-SECURIS-ERROR";
23
+ public static final int DEFAULT_APP_ERROR_STATUS_CODE = 418;
24
+ public static final String ERROR_MESSAGE_HEADER = "X-SECURIS-ERROR-MSG";
25
+ public static final String ERROR_CODE_MESSAGE_HEADER = "X-SECURIS-ERROR-CODE";
2326
2427 public DefaultExceptionHandler() {
2528 LOG.info("Creating DefaultExceptionHandler ");
....@@ -34,13 +37,17 @@
3437 public Response toResponse(Exception e) {
3538 if (e instanceof ForbiddenException) {
3639 LOG.warn("Unauthorized access to {}, user: {}", request.getPathInfo(), bsc.getUserPrincipal());
37
- return Response.status(Status.UNAUTHORIZED).header(ERROR_MESSAGE_HEADER, "Unathorized access to the application")
40
+ return Response.status(Status.UNAUTHORIZED)
41
+ .header(ERROR_CODE_MESSAGE_HEADER, ErrorCodes.INVALID_CREDENTIALS)
42
+ .header(ERROR_MESSAGE_HEADER, "Unathorized access to the application")
3843 .type(MediaType.APPLICATION_JSON).build();
3944 }
4045
4146 if (e instanceof SeCurisServiceException) {
4247 LOG.warn("SeCurisServiceException accessing to {}, user: {}", request.getPathInfo(), bsc.getUserPrincipal());
43
- return Response.status(Status.fromStatusCode(((SeCurisServiceException) e).getStatus())).header(ERROR_MESSAGE_HEADER, e.getMessage())
48
+ return Response.status(DEFAULT_APP_ERROR_STATUS_CODE)
49
+ .header(ERROR_CODE_MESSAGE_HEADER, ((SeCurisServiceException) e).getStatus())
50
+ .header(ERROR_MESSAGE_HEADER, e.getMessage())
4451 .type(MediaType.APPLICATION_JSON).build();
4552 }
4653