Module: Core/Error

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);

Members


<static> errorName2Keys

Maps validator names to error labels.


<static> statusCodes :Core/Error.StatusCodes

Type:

Methods


<static> enableOnError(handler, context)

Binds a custom handler for window.onerror event. Does nothing if it has already been overloaded.

Calls the provided handler, or falls back to {Core.Error#handleUnhandledError} and then calls the original handler if defined.

Parameters:
Name Type Description
handler function

Callback function to call on error.

context Object

The scope of the handler.

Returns:

false if onerror has already been overloaded.

Type
boolean

<static> getErrorString(errorKey [, context])

Returns error strings given a error key and context.

Parameters:
Name Type Argument Description
errorKey string

The error key we want to get the error message from.

context Object <optional>

The template context to pass to the string/template.

Returns:

The i18n error string associated with the given errorKey and filled in by the context.

Type
string

<static> handleHttpError(error, model, options)

Handles http errors returned from AJAX calls.

This method calls the relevant handler function using {Core.Error#statusCodes}

Parameters:
Name Type Description
error Api.HttpError

AJAX error.

model Data/Bean | Data/BeanCollection

The model or collection on which the request was made.

options Object

A hash of options.


<static> handleRenderError(component, method [, additionalInfo])

Handles render related errors.

Parameters:
Name Type Argument Description
component View/Component

The component that triggered the error.

method string

The method that caught the error. Example: _renderHtml.

additionalInfo string <optional>

Any additional information relevant for that particular method.


<static> handleStatusCodesFallback(error)

This is the fallback error handler if the custom status code specific handler is not implemented. To define custom error handlers, you should include your script from index page and do something like:

Parameters:
Name Type Description
error string

The AJAX error.


<static> handleUnhandledError(message, url, line)

Handles unhandled javascript exceptions which are reported via window.onerror event.

The default implementation logs the error with level FATAL.

Parameters:
Name Type Description
message string

Error message.

url string

URL of script.

line string

Line number of script.


<static> handleValidationError(error)

Handles validation errors.

By default this just pipes the error to the error logger.

Parameters:
Name Type Description
error Api.HttpError

The AJAX error.


<static> init()

Binds a window.onerror callback to log error using sidecar's logger.


<static> initialize(opts)

Sets properties and binds a window.onerror callback to log error using the logger.

Parameters:
Name Type Description
opts Object

A hash of options.

Deprecated:
  • since 7.10.

<static> throwErrorWithCallStack(error [, skipThrow])

Inserts call stack string to Error message. window.onerror handler is not provided with Error object (4th argument) in Safari.

Parameters:
Name Type Argument Default Description
error string | Error

Error text or Error object.

skipThrow boolean <optional>
false

If true, skips exception raising.

Deprecated:
  • since 7.10.
Returns:

Error object with stack trace inserted into Error.message property.

Type
Error