class SecurityErrorCheck implements ErrorCheck {

    @Override
    public ResponseEntity<ApiMessageView> checkError(HttpServletRequest request, Throwable exc) {
        if (exc instanceof ZuulException && (exc.getCause() instanceof AuthenticationException)) {
            ApiMessageView messageView = null;
            Throwable cause = exc.getCause();
            if (cause instanceof TokenExpireException) {
                messageView = messageService.createMessage("org.zowe.apiml.gateway.security.expiredToken").mapToView();
            } else if (cause instanceof TokenNotValidException) {
                messageView = messageService.createMessage("org.zowe.apiml.gateway.security.invalidToken").mapToView();
            } else if (cause instanceof BadCredentialsException) {
                messageView = messageService.createMessage("org.zowe.apiml.security.login.invalidCredentials",
                    ErrorUtils.getGatewayUri(request)
                ).mapToView();
            }
            return ResponseEntity.status(HttpStatus.UNAUTHORIZED).contentType(MediaType.APPLICATION_JSON_UTF8).body(messageView);
        }

        return null;
    }

}