class ServiceErrorCheck implements ErrorCheck {

    @Override
    public ResponseEntity<ApiMessageView> checkError(HttpServletRequest request, Throwable exc) {
        if (exc instanceof ZuulException) {
            ZuulException exception = (ZuulException) exc;
            ApiMessageView messageView = null;
            if (exc.getCause() instanceof ServiceNotAccessibleException) {
                Throwable t = ExceptionUtils.getThrowables(exc)[ExceptionUtils.indexOfType(exc, ServiceNotAccessibleException.class)];
                messageView = messageService.createMessage("org.zowe.apiml.gateway.serviceUnavailable",
                    ErrorUtils.getGatewayUri(request),
                    t.getCause()
                ).mapToView();
                return ResponseEntity.status(HttpStatus.NOT_FOUND).contentType(MediaType.APPLICATION_JSON_UTF8).body(messageView);
            } else if (exception.nStatusCode == HttpStatus.NOT_FOUND.value()) {
                messageView = messageService.createMessage("org.zowe.apiml.common.endPointNotFound", exception.errorCause).mapToView();
                return ResponseEntity.status(HttpStatus.NOT_FOUND).contentType(MediaType.APPLICATION_JSON_UTF8).body(messageView);
            }
        }

        return null;
    }

}