| .. | .. |
|---|
| 11 | 11 | import javax.ws.rs.ext.Provider; |
|---|
| 12 | 12 | |
|---|
| 13 | 13 | import net.curisit.securis.services.exception.SeCurisServiceException; |
|---|
| 14 | +import net.curisit.securis.services.exception.SeCurisServiceException.ErrorCodes; |
|---|
| 14 | 15 | |
|---|
| 15 | 16 | import org.apache.logging.log4j.LogManager; |
|---|
| 16 | 17 | import org.apache.logging.log4j.Logger; |
|---|
| .. | .. |
|---|
| 19 | 20 | public class DefaultExceptionHandler implements ExceptionMapper<Exception> { |
|---|
| 20 | 21 | private static final Logger LOG = LogManager.getLogger(DefaultExceptionHandler.class); |
|---|
| 21 | 22 | |
|---|
| 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"; |
|---|
| 23 | 26 | |
|---|
| 24 | 27 | public DefaultExceptionHandler() { |
|---|
| 25 | 28 | LOG.info("Creating DefaultExceptionHandler "); |
|---|
| .. | .. |
|---|
| 34 | 37 | public Response toResponse(Exception e) { |
|---|
| 35 | 38 | if (e instanceof ForbiddenException) { |
|---|
| 36 | 39 | 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") |
|---|
| 38 | 43 | .type(MediaType.APPLICATION_JSON).build(); |
|---|
| 39 | 44 | } |
|---|
| 40 | 45 | |
|---|
| 41 | 46 | if (e instanceof SeCurisServiceException) { |
|---|
| 42 | 47 | 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()) |
|---|
| 44 | 51 | .type(MediaType.APPLICATION_JSON).build(); |
|---|
| 45 | 52 | } |
|---|
| 46 | 53 | |
|---|