Socket
Book a DemoInstallSign in
Socket

res-error

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

res-error

Adds a super flexible res.error() method to express that logs an error and sends the correct JSON response to the client

0.3.1
latest
Source
npmnpm
Version published
Weekly downloads
5
400%
Maintainers
1
Weekly downloads
 
Created
Source

#res-error

This package adds a super flexible res.error() method to express that logs an error and sends the correct JSON response to the client

##Installing

  • Run npm install res-error --save in your project directory
  • Apply it as middleware to your app (before the router):

var app = express(); app.use(require('res-error')); ... ````

##Usage

The response object will now contain an error method which can be passed a code, message string, and/or error object.

app.get('/path', function(res, req){

	// something happens here that might set err
	
	if(err)
		return res.error(err);
	
	return res.send('There wasn\'t an error.');
});

It's very flexible. Here are more examples:

res.error(404);

res.error(err);

res.error(404, err);

res.error(404, 'Ooh, we couldn\'t find that.');

res.error(404, err, 'Ooh, we couldn\'t find that.');

res.error(404, {message: 'Ooh, we couldn\'t find that.', hidden: 'foo'});

res.error(404, {message: 'Masked message', hidden: 'foo'}, 'Ooh, we couldn\'t find that.');

res.error({code: 404, message: 'Ooh, we couldn\'t find that.', hidden: 'foo'});

##Oh no, I found a bug!

Please submit an issue! :)

Keywords

express

FAQs

Package last updated on 28 Jul 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.