@Override
    public Response toResponse(AbstractEngineException data) {
        int errorCode;
        if (data instanceof IStatusCode) {
            errorCode = ((IStatusCode) data).getStatusCode();
        } else {
            errorCode = mapExceptionToHttpErrorCode(data);
        }
        GatewayApiErrorBean error = new GatewayApiErrorBean();
        error.setErrorType(data.getClass().getSimpleName());
        error.setMessage(data.getMessage());
        error.setStacktrace(getStackTrace(data));
        ResponseBuilder builder = Response.status(errorCode).header("X-API-Gateway-Error", "true"); //$NON-NLS-1$ //$NON-NLS-2$
        builder.type(MediaType.APPLICATION_JSON_TYPE);
        return builder.entity(error).build();
    }
@see javax.ws.rs.ext.ExceptionMapper#toResponse(java.lang.Throwable)
gateway/api/rest-impl/src/main/java/io/apiman/gateway/api/rest/impl/mappers/RestExceptionMapper.java