class AuthenticationServiceV1 {

    protected Response handleErrorResponse(Request request, Status status, Exception exception) {
        Reject.ifNull(status);
        Response response = new Response(status);
        final Map<String, Object> rep = new HashMap<>();
        if (exception instanceof RestAuthResponseException) {
            final RestAuthResponseException authResponseException = (RestAuthResponseException) exception;
            for (Map.Entry<String, String> entry : authResponseException.getResponseHeaders().entrySet()) {
                response.getHeaders().put(entry.getKey(), entry.getValue());
            }
            rep.putAll(authResponseException.getJsonResponse().asMap());

        } else if (exception instanceof RestAuthException) {
            final RestAuthException authException = (RestAuthException)exception;
            if (authException.getFailureUrl() != null) {
                rep.put("failureUrl", authException.getFailureUrl());
            }
            rep.put("errorMessage", getLocalizedMessage(request, exception));

        } else if (exception == null) {
            rep.put("errorMessage", status.getReasonPhrase());
        } else {
            rep.put("errorMessage", getLocalizedMessage(request, exception));
        }

        response.setEntity(rep);

        return response;
    }

    @Inject public  AuthenticationServiceV1(RestAuthenticationHandler restAuthenticationHandler);

}