GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - IBM/message-catalog-manager: message-catalog-manager

BranchesTags
Open more actions menu

Latest commit

 

History

92 Commits
92 Commits

Folders and files

NameName
Last commit message
Last commit date
.github/workflows
.github/workflows
 
 
example/errorMiddlewareApp
example/errorMiddlewareApp
 
 
lib
lib
 
 
test
test
 
 
.eslintignore
.eslintignore
 
 
.eslintrc
.eslintrc
 
 
.gitignore
.gitignore
 
 
.npmignore
.npmignore
 
 
.travis.yml
.travis.yml
 
 
.whitesource
.whitesource
 
 
CONDUCT.md
CONDUCT.md
 
 
CONTRIBUTING.md
CONTRIBUTING.md
 
 
DCO1.1.txt
DCO1.1.txt
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
index.js
index.js
 
 
package.json
package.json
 
 

Repository files navigation

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

var MessageCatalogManager = require("message-catalog-manager").MessageCatalogManager;
var catalogManager = new MessageCatalogManager("/catalog-index.json");
var formattedMessage = catalogManager.getMessage("catalog1", "0001", {}, ["myapp"]);

Using catalogedError

var CatalogedError = require("message-catalog").CatalogedError;
throw 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.

app.use(new ErrorFormattingMiddleware('catalog-index.json'));

There is a simple application that always responds with a CatalogedError in example. Start it like

node example/errorMiddlewareApp/errorMiddlewareApp.js

Release Notes

v1.0.0

  • Initial release

v2.0.0

  • Positional and named inserts can now be of type: undefined and object, in addition to string, number, boolean Objects and arrays will be stringified with the normal toString()
  • catalogedError constructor will throw for unsupported insert types

v2.1.0

  • Classes MessageCatalogManager and CatalogedError are exported with a capitalised class names
  • The message identifier for a CatalogedError instance renamed messageCode instead of messageNumber (it's type is string)
  • formattingMiddleware should be called as a function (not with new)
  • formattingMiddleware supports an optional function to transform messages before formatting:
    function myTransform(msg){
      // transform msg as required
      return msg;
    }
    app.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)

v2.2.0

  • getMessage support for returning a data object.
    • Build data using a regex pattern matching keys in the namedInserts
    • Build data using a static definition in the catalog entry

About

message-catalog-manager

Topics

catalogcatalog-managermessage-catalogstranslate

Resources

Readme
MIT license

Contributing

Contributing

Security policy

Security policy
Activity
Custom properties

Stars

2 stars

Watchers

9 watching

Forks

14 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.