my-error

Custom Error class for `util.inherits`

Usage no npm install needed!

<script type="module">
  import myError from 'https://cdn.skypack.dev/my-error';
</script>

README

my-error

build npm npm npm

Custom Error class for util.inherits.

Installation

npm install my-error --save

Usage

var MyError = require('my-error');


// create your custom error
function CodeError(code, message) {
  CodeError.super_.call(this, message);
  this.code = code;
}
util.inherits(CodeError, MyError);
// later on..
try {
  throw new CodeError(404, 'Not Found!');
} catch (err) {
  // do some thing...

  // err.name === 'CodeError';
  // err.code === 404;
  // err.message === 'Not Found!';
  
  // err instanceof CodeError;
  // err instanceof Error;
}

License

Copyright © 2015 Moshe Simantov ms@development.co.il, MIT License