gpii-universal
Version:
Cross platform, core components of the GPII personalization infrastructure.
55 lines (48 loc) • 2.63 kB
JavaScript
/*
* GPII User Errors
*
* Copyright 2018 Raising the Floor - International
*
* Licensed under the New BSD license. You may not use this file except in
* compliance with this License.
*
* You may obtain a copy of the License at
* https://github.com/GPII/universal/blob/master/LICENSE.txt
*/
;
var fluid = fluid || require("infusion"),
gpii = fluid.registerNamespace("gpii");
fluid.registerNamespace("gpii.userErrors");
/** The channel for receiving and transmitting errors from the core GPII architecture which are of interest to end
* users and which could/should be surfaced at the UI level. Any component wishing to signal such an error should
* fire the `userError` event held here, with an Error payload including (at least) fields:
* {Boolean} isError - Holding the value `true` identifying the payload as an error
* {String} messageKey - A key for the message displayed to the user, which is indirected into the message bundle
* held in ../bundles/gpii-userErrors-messageBundle_xx.json5 by the following process:
* i) The prefix gpii-userErrors_ is added
* ii) The three suffices -title, -subhead and -details each lead to descriptions of the error at successive layers
* of detail.
* {Object} [originalError] - [optional] Any upstream error object that led to this error being fired.
* The current common architecture document describing the available errors and their purposes is held at
* [GPII Error Messages Spreadsheet](https://docs.google.com/spreadsheets/d/1ybyf9xoYoArjswWBhhBWECrrJdTPspI6FAuzjtcNmsM/edit) and the UX
* designs showing the three forms of message displayed in the PSP are at
* [Style Guide for Error Messages](https://docs.google.com/document/d/1rTMjpwH8d9HQ6hXoG6-qlsuf9F7oX-s37MJclFHgCYE/edit)
*/
fluid.defaults("gpii.userErrors", {
gradeNames: "fluid.component",
events: {
// Fired with an Error payload when an error representing a user error is to be signalled
userError: null
}
});
// The constant that defines the node.js error code indicating connection problems.
gpii.userErrors.connectionErrorCode = ["ECONNREFUSED", "ETIMEDOUT", "ECONNRESET", "ENOTFOUND"];
/**
* Check if the given error code indicates a connection problem. Return true if the code does indicate a connection
* problem. Otherwise, return false.
* @param {String} code - An node.js error code.
* @return {Boolean} Return true if the code does indicate a connection problem. Otherwise, return false.
*/
gpii.userErrors.isConnectionError = function (code) {
return gpii.userErrors.connectionErrorCode.indexOf(code) !== -1;
};