Error manager for XHR errors.
This module allows you to provide custom handling depending on the
xhr error.
Below is the exhaustive list of functions you can implement, with the
description of the error it will handle:
Authentication error handler functions
OAuth2 uses 400 error to catch all authentication errors; see:
http://tools.ietf.org/html/draft-ietf-oauth-v2-20#section-5.2
handleInvalidGrantError
The provided authorization grant is invalid, expired, revoked, does
not match the redirection URI used in the authorization request, or
was issued to another client. Note that the server implementation
will override invalid_grant as needs_login as a special case (see below).
handleNeedLoginError
The server shall use this in place of invalid_grant to tell client to
handle error specifically as caused due to invalid credentials being
supplied. The reason server needs to use this is because an invalid_grant
oauth error may also be caused by invalid or expired token.
Using needs_login allows all clients to provide proper messaging to end
user without the need for extra logic.
handleInvalidClientError
Client authentication failed (e.g. unknown client, no client
authentication included, multiple client authentications included,
or unsupported authentication method).
handleInvalidRequestError
The request is missing a required parameter, includes an unsupported
parameter or parameter value, repeats a parameter, includes multiple
credentials, utilizes more than one mechanism for authenticating the
client, or is otherwise malformed.
handleUnauthorizedClientError
The authenticated client is not authorized to use this authorization
grant type.
handleUnsupportedGrantTypeError
The authorization grant type is not supported by the authorization
server.
handleInvalidScopeError
The requested scope is invalid, unknown, malformed, or exceeds the scope
granted by the resource owner.
Other error handler functions.
handleTimeoutError
handleUnspecified400Error
handleUnauthorizedError
handleForbiddenError
handleNotFoundError
handleMethodNotAllowedError
handleMethodConflictError
handleHeaderPreconditionFailed
handleValidationError
handleMethodFailure
ErrorhandleServerError
``
Example of usage:
const Handlers = {
handleTimeoutError: function() {
console.log('The request has timed out.')
},
handleServerError: function() {
console.log('Something went wrong with the server, please contact
your admin');
}
}
const ErrorHandler = _.extend(require('core/error'), Handlers);