module:nmodule/js/rc/errors/LocalizableError

module:nmodule/js/rc/errors/LocalizableError

Provides a simple means of throwing, or rejecting with, an Error that is intended to be
displayed to the user.

(Previously, in order to both throw an error and display an error dialog to the user, you
would have to do it in two steps: display the error dialog with feDialogs.error or similar,
and then throw the actual error so the Promise itself would reject.)

To use LocalizableError, simply create and throw an instance of it. Many places in the
framework are capable of handling LocalizableError and displaying it to the user:

  • The log! plugin
  • baja.error()
  • feDialogs.error()
  • And transitively, any functionality in the UI that is configured to log/display Errors
    through these APIs, including:
    • Command instances that are invoked through CommandButtons (via the HTML5 Hx Profile,
      Manager views, etc.)
    • Hyperlinking between views

It follows that if you display the error yourself, and also throw it:

this.validators().add((value) => {
  if (value > max) {
    const err = new LocalizableError('%lexicon(myModule:valueTooBig)%');
    return feDialogs.error(err)
      .then(() => { throw err; });
  }
});

the framework will not know that you already displayed the error, and will display it a second
time. LocalizableError is intended to simply be thrown by your code, not displayed and
thrown.

Constructor

new (require("nmodule/js/rc/errors/LocalizableError"))(params)

Description:
  • Creates a LocalizableError

Source:
Since:
  • Niagara 4.14
Extends:
  • Error
Parameters:
Name Type Description
params String | Object

either an error message as a string or an object that contains
the values for a formatted error

Properties
Name Type Attributes Description
module String <optional>

the module name to use for looking up the lexicon entries

lex String <optional>

the lexicon key to look up the error message components

title String <optional>

the title for the error. If both lexicon information and title
is supplied the title overrides any title found in the lexicon. This can be in the format of
a Lexicon format. For instance, %lexicon(moduleName:keyName)%.

titleArgs Array.<*> <optional>

an array of value to be passed to the 'lex.format' command
to complete the title. Only works with module and lex.

summaryMessage String <optional>

the summaryMessage for the error that is prepended to
the error message. If both lexicon information and summaryMessage is supplied the summaryMessage
overrides any summaryMessage found in the lexicon This can be in the format of * a Lexicon
format. For instance, %lexicon(moduleName:keyName)%.

summaryArgs Array.<*> <optional>

an array of value to be passed to the 'lex.format'
command to complete the summary message. Only works with module and lex.

message String <optional>

the error message for the error. If both lexicon
information and message is supplied the message overrides any message found in the lexicon
This can be in the format of a Lexicon format. For instance, %lexicon(moduleName:keyName)%.

messageArgs Array.<*> <optional>

an array of value to be passed to the 'lex.format' command
to complete the message. Only works with module and lex.

Extends

  • Error

Methods

toMessage() → {Promise.<String>}

Description:
  • Resolves the message for the error

Source:
Returns:
Type
Promise.<String>

toStack() → {Promise.<string>}

Description:
  • Resolves to a formatted string that holds the error stack

Source:
Returns:
Type
Promise.<string>

toSummaryMessage() → {Promise.<String>}

Description:
  • Resolves the message summary for the error

Source:
Returns:
Type
Promise.<String>

toTitle() → {Promise.<String>}

Description:
  • Resolves the title for the error

Source:
Returns:
Type
Promise.<String>