IBM/message-catalog-manager

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

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

message-catalog-manager

Build Status Coverage Status

Overview

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.

Catalog file format

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

Using message-catalog-manager
MessageCatalogManager = require("message-catalog-manager").MessageCatalogManager;
catalogManager = new MessageCatalogManager("/catalog-index.json");
formattedMessage = catalogManager.getMessage("catalog1", "0001", {}, ["myapp"]);
Using catalogedError
CatalogedError = require("message-catalog").CatalogedError;
w new CatalogedError("0001", "catalog1", "An error occurred", ["myapp"]);
Express Middleware

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
Release Notes

v1.0.0

v2.0.0

v2.1.0


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.