Name: message-catalog-manager
Owner: International Business Machines
Description: message-catalog-manager
Created: 2016-10-25 14:05:08.0
Updated: 2018-04-18 13:34:28.0
Pushed: 2018-04-18 13:34:27.0
Homepage: null
Size: 79
Language: JavaScript
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
This module provides a mechanism for translating messages to provide user readable information. Messages support named and positional inserts to give context to the messages. Messages can include messages and actions, as well as urls for more information. A catloggedError class carries catalog message context information so errors thrown around a system can be translated at the appropriate point.
The catalog manager works with a set of json message catalog files contain message text. These are indexed in a separate catalog index file which is provided to the catalog manager.
For an example of the catalog file format see: messages.json For an example of the catalog index file format see: catalog-index.json
MessageCatalogManager = require("message-catalog-manager").MessageCatalogManager;
catalogManager = new MessageCatalogManager("/catalog-index.json");
formattedMessage = catalogManager.getMessage("catalog1", "0001", {}, ["myapp"]);
CatalogedError = require("message-catalog").CatalogedError;
w new CatalogedError("0001", "catalog1", "An error occurred", ["myapp"]);
If your Express application generates or receives a CatalogedError
you can use the formattingMiddleware
middleware to intercept all responses and attempt to format error responses before they are sent.
use(new ErrorFormattingMiddleware('catalog-index.json'));
There is a simple application that always responds with a CatalogedError
in example. Start it like
example/errorMiddlewareApp/errorMiddlewareApp.js
v1.0.0
v2.0.0
toString()
catalogedError
constructor will throw for unsupported insert typesv2.1.0
MessageCatalogManager
and CatalogedError
are exported with a capitalised class namesCatalogedError
instance renamed messageCode
instead of messageNumber
(it's type is string)new
)tion myTransform(msg){
transform msg as required
turn msg;
use(messageCatalogManager.formattingMiddleware('catalog-index.json', myTransform));
The function can be synchronous (return a transformed message object) or asynchronous (return a promise to a
transformed message object)