Code Monkey home page Code Monkey logo

errors's People

Contributors

bodenr avatar creynders avatar joepie91 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

errors's Issues

Feature: pass properties object to constructor.

example:

errors.Http401Error({message:"Expired Token", expired:someDate});

Would set the message property, as well as including an expired property on the output. I find the act of sending multiple strings to the constructor a bit disturbing for example.

`express` dependency requirement

By including express in the list of dependencies in package.json, it makes express a required dependency of the package. That means that the checks in lib/errors.js will always load the errorHandler middleware despite the attempts to only provide the feature if the express module is available.

I really like the feature of express being conditionally loaded as then this library can be used outside of node.js too. Was it intended to make express a requirement of this package?

Major version increase?

The last release bumped the major version number, but it's not obvious to me why, and there doesn't appear to be a changelog. What is the possible break?

Stack trace doesn't include error message in Node 5

Code:

var errors = require('errors');
errors.create({ name: 'FooError' });
throw new errors.FooError('custom message');

Output:

myndzi@tetrisguide:~/foo$ node -v
v0.10.33
myndzi@tetrisguide:~/foo$ node test

/home/myndzi/foo/test.js:7
throw new errors.FooError('custom message');
      ^
Error: custom message
    at Object.<anonymous> (/home/myndzi/foo/test.js:7: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
myndzi@seckzi:~/conjoined$ node -v
v5.3.0
myndzi@seckzi:~/conjoined$ node errorstest.js

/home/myndzi/conjoined/errorstest.js:7
throw new errors.FooError('custom message');
^
Error
    at Object.<anonymous> (/home/myndzi/conjoined/errorstest.js:7:7)
    at Module._compile (module.js:398:26)
    at Object.Module._extensions..js (module.js:405:10)
    at Module.load (module.js:344:32)
    at Function.Module._load (module.js:301:12)
    at Function.Module.runMain (module.js:430:10)
    at startup (node.js:141:18)
    at node.js:980:3

Ability to wrap errors

I want to wrap a low-level error with another error, and have errors's "stack" setting to affect how it's printed.

var fs = require('fs');
var errors = require('errors');

function doSomeImportantThing(filename, cb) {
  lowLevelFileSystemThing(filename, function(err) {
    var newErr =  new (errors.find('SomeImportantFailure'))({
      cause: err
    });

   console.log(newError.toJSON());
  });
}

stack is false:

{
   "cause": {
     "message": "lowLevelFileSystemThing failed foobarred $filename"
   },
  "code": "600",
  "message": "SomeImportantThing Failed",
  "name": "SomeImportFailure"
}

stack is true:

{
   "cause": {
     "message": "lowLevelFileSystemThing foobarred $filename",
     "stack":  ""
   },
  "code": "600",
  "message": "SomeImportantThing Failed",
  "name": "SomeImportFailure",
  "stack": ""
}

The current output prints the "stack" in all cases.

Error doesn't inherit status code from Http400Error

var errors = require('errors');

errors.create({
  name: 'ValidationError',
  defaultMessage: 'Validation error',
  defaultExplanation: 'Some properties are not valid',
  defaultResponse: 'Resend the object with valid properties',
  parent: errors.Http400Error
});

// Status property is 500 instead of 400.
console.log(new errors.ValidationError())

Is there a way to fix this?

How to use `errorHandler` in an express-based framework

I'm working on a project using keystone.js. In case you don't know it, it's an express-based CMS. I wanted to integrate the 'errors'-module, however noticed I can't use errors.errorHandler middleware. I think this is due to https://github.com/bodenr/errors/blob/master/lib/errors.js#L643
It checks for the presence of 'express' or 'connect' and only exports errorHandler in case one of those is found. However since my project doesn't depend on express directly neither express nor connect are found and the errorHandler isn't exposed. Obviously I could add express to my dependencies, but I'd rather not, since it isn't used anywhere else.

Do you know of a workaround? ATM I simply don't use any of the express integration, but that's a bit of a shame IMO.

How to override only a specific default?

Is there a way to override only a specific default property? Since in some cases I just want to override the explanation or response.

var errors = require('errors');

errors.create({
  name: 'ValidationError',
  defaultMessage: 'Validation error',
  defaultExplanation: 'Some properties are not valid',
  defaultResponse: 'Resend the object with valid properties',
  parent: errors.Http400Request
});

var validationError = new error.ValidationError();

// TypeError: Cannot assign to read only property
validationError.explanation = 'My new explanation';

Feature: message property templating

It would be nice to have the message string as a template against the other properties of the object... (suggest ES6 string template format, lodash has an implementation)

example:

errors.create({
  name: 'DocumentNotFound',
  message: 'The document "${document}" was not found.'
});

console.log(new errors.DocumentNotFound({ document: 'path/to/document.ext' }))

would output:

code: 6xx
name: 'DocumentNotFound'
message: 'The document "path/to/document.ext" was not found'

Idea burrowed from error/typed

//using lodash's _.template
  ...
  if ((/\$\{[^\}]+\}/).test(this.message)) {
    this.message = _.template(this.message, this);
  }
} //end of constructor method

Making lodash a dependency without a version specified to allow for npm dedupe in a hosting package to always work, with a very slim risk of an incompatible version.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.