Skip to content

Instantly share code, notes, and snippets.

@mxriverlynn
Created May 15, 2016 22:00
Show Gist options
  • Save mxriverlynn/c69096c7970ba18ecc3d09969b098f3d to your computer and use it in GitHub Desktop.
Save mxriverlynn/c69096c7970ba18ecc3d09969b098f3d to your computer and use it in GitHub Desktop.
custom error with clean stack trace
function createError(msg, status){
var err = new Error(msg);
err.status = status;
// uncomment this next line to get a clean stack trace in node.js
// Error.captureStackTrace(err, createError);
return err;
}
var err = createError("test", 500);
throw err;
@JasonCust
Copy link

I have used a similar pattern in the past to create specific error types: https://github.com/CentralPing/errors/blob/master/errors.js

They can be very useful when employing a universal error handler to determine programmatically how to issue an error response.

@Knighton910
Copy link

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment