Important

You are browsing the documentation for version 4.1 of OroCommerce, OroCRM and OroPlatform, which is no longer maintained. Read version 5.1 (the latest LTS version) of the Oro documentation to get up-to-date information.

See our Release Process documentation for more information on the currently supported and upcoming releases.

Error Handler

Error Handler provides a generalized system display of errors in the application. It allows to show different error formats for prod and dev environment.

How to Use It

Import oroui/js/error into your component:

1 define(function(require) {
2     'use strict';
3
4     var error = require('oroui/js/error');
5
6     /* Another code */
7 });

To display an error message, use the methods provided in Error Handler

showError

Options:

  • context: {Object|Error}

  • errorMessage: {String|null} _(optional)_

Description:

Show an error both in the UI Flash Message and Console

showErrorInUI

Options:

  • context: {Object|Error|String}

Description:

Show an error only in UI Flash Message. If context is Error, then in prod env the output is a simple message, but in dev env additional debug information can be shown.

showErrorInConsole

Options:

  • context: {Object|Error}

Description:

Show an error only in Console

showFlashError

Options:

  • message: {String}

Description:

Show a simple Error Flash Message

modalHandler

Options:

  • xhr: {Object|Error}

Description:

Show an error only in modal

Default Options

The following options can be redefined when calling the error module

headerServerError

  • Type: {String}

  • Default: ‘Server error’

Description:

Used as the modal title in modalHandler method if the error comes from the server

headerUserError

  • Type: {String}

  • Default: ‘User input error’

Description:

Used as the modal title in modalHandler method if it is a user error

message

  • Type: {String}

  • Default: ‘There was an error performing the requested operation. Please try again or contact us for assistance.’

Description:

Default error text message

loginRoute

  • Type: {String}

  • Default: ‘oro_user_security_login’

Description:

Specifies the redirect url if XHR status is 401

Error Handler and $.ajax() errors

By default, Error Handler catches and shows all default errors provided by $.ajax(). However, developers can change or disable this behavior by adding the errorHandlerMessage option into ajax settings.

errorHandlerMessage

  • Type: {Boolean|String|Function}

  • Default: true

Disable ajax Error Flash Message:

1$.ajax({
2    url: 'test',
3    errorHandlerMessage: false
4});

Set a custom error message:

1$.ajax({
2    url: 'test',
3    errorHandlerMessage: "Custom Error Message"
4});

Callback function can also be used for errorHandlerMessage:

1$.ajax({
2    url: 'test',
3    errorHandlerMessage: function(event, xhr, settings) {
4        // Suppress error if it's 404 response
5        return xhr.status !== 404;
6    }
7});