From b77838d1005c45740968816c70088dff2ad655d3 Mon Sep 17 00:00:00 2001
From: rsanchez <rsanchez@curisit.net>
Date: Thu, 25 Sep 2014 16:41:34 +0000
Subject: [PATCH] #2021 fix - Added API services and some minor enhancements

---
 securis/src/main/java/net/curisit/securis/DefaultExceptionHandler.java |   13 ++++++++++---
 1 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/securis/src/main/java/net/curisit/securis/DefaultExceptionHandler.java b/securis/src/main/java/net/curisit/securis/DefaultExceptionHandler.java
index 6d2ed11..fc29955 100644
--- a/securis/src/main/java/net/curisit/securis/DefaultExceptionHandler.java
+++ b/securis/src/main/java/net/curisit/securis/DefaultExceptionHandler.java
@@ -11,6 +11,7 @@
 import javax.ws.rs.ext.Provider;
 
 import net.curisit.securis.services.exception.SeCurisServiceException;
+import net.curisit.securis.services.exception.SeCurisServiceException.ErrorCodes;
 
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
@@ -19,7 +20,9 @@
 public class DefaultExceptionHandler implements ExceptionMapper<Exception> {
     private static final Logger LOG = LogManager.getLogger(DefaultExceptionHandler.class);
 
-    public static final String ERROR_MESSAGE_HEADER = "X-SECURIS-ERROR";
+    public static final int DEFAULT_APP_ERROR_STATUS_CODE = 418;
+    public static final String ERROR_MESSAGE_HEADER = "X-SECURIS-ERROR-MSG";
+    public static final String ERROR_CODE_MESSAGE_HEADER = "X-SECURIS-ERROR-CODE";
 
     public DefaultExceptionHandler() {
         LOG.info("Creating DefaultExceptionHandler ");
@@ -34,13 +37,17 @@
     public Response toResponse(Exception e) {
         if (e instanceof ForbiddenException) {
             LOG.warn("Unauthorized access to {}, user: {}", request.getPathInfo(), bsc.getUserPrincipal());
-            return Response.status(Status.UNAUTHORIZED).header(ERROR_MESSAGE_HEADER, "Unathorized access to the application")
+            return Response.status(Status.UNAUTHORIZED)
+                    .header(ERROR_CODE_MESSAGE_HEADER, ErrorCodes.INVALID_CREDENTIALS)
+                    .header(ERROR_MESSAGE_HEADER, "Unathorized access to the application")
                     .type(MediaType.APPLICATION_JSON).build();
         }
 
         if (e instanceof SeCurisServiceException) {
             LOG.warn("SeCurisServiceException accessing to {}, user: {}", request.getPathInfo(), bsc.getUserPrincipal());
-            return Response.status(Status.fromStatusCode(((SeCurisServiceException) e).getStatus())).header(ERROR_MESSAGE_HEADER, e.getMessage())
+            return Response.status(DEFAULT_APP_ERROR_STATUS_CODE)
+                    .header(ERROR_CODE_MESSAGE_HEADER, ((SeCurisServiceException) e).getStatus())
+                    .header(ERROR_MESSAGE_HEADER, e.getMessage())
                     .type(MediaType.APPLICATION_JSON).build();
         }
 

--
Gitblit v1.3.2