Skip to content
/ erroz Public
forked from peerigon/erroz

Create abstract errors with meta-data, stack-traces and speaking error-messages.

License

Notifications You must be signed in to change notification settings

topa/erroz

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

erroz

Erroz ramazotti the way you like it.

Create abstract errors with meta-data, stack-traces and speaking error-messages.

Usage

Templated Error Message

By setting a template property you can define a dynamic-error-message. The message will be generated by rendering the template with an object passed on Error construction. i.e. new Error({ resource: "User" });

var erroz = require("erroz");

var NotFoundError = erroz({
    name: "NotFound",
    code: "not-found",
    status: "fail",
    statusCode: 404,
    template: "%resource (%id) not found"
});

throw new NotFoundError({ resource: "User", id: 1 });

/*
/erroz/examples/customTemplateRenderer.js:22
 throw new NotFoundError({ resource: "User", id: 1 });
       ^
 NotFound: User (1) not found
     at Object.<anonymous> (/erroz/examples/customTemplateRenderer.js:22:7)
     at Module._compile (module.js:456:26)
     at Object.Module._extensions..js (module.js:474:10)
     at Module.load (module.js:356:32)
     at Function.Module._load (module.js:312:12)
     at Function.Module.runMain (module.js:497:10)
     at startup (node.js:119:16)
     at node.js:906:3
*/

Static Error-Message

By setting a message property you can define a static error message.

var DuplicateError = erroz({
    name: "Duplicate",
    code: "duplicate",
    status: "fail",
    statusCode: 409,
    message: "Resource already exists"
});

throw new DuplicateError();

/*
 throw new DuplicateError();
 ^
 Duplicate: Resource already exists
 at Object.<anonymous> (/erroz/examples/staticErrorMessage.js:14:7)
 at Module._compile (module.js:456:26)
 at Object.Module._extensions..js (module.js:474:10)
 at Module.load (module.js:356:32)
 at Function.Module._load (module.js:312:12)
 at Function.Module.runMain (module.js:497:10)
 at startup (node.js:119:16)
 at node.js:902:3
 */

About

Create abstract errors with meta-data, stack-traces and speaking error-messages.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%