Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

apis-return

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

apis-return

Return value apis helper

  • 0.2.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

#apis-return

Return value helper for apis lib

##Usage

var returnHandler = require('apis-return');

//Some resource class here
Resource.prototype.get = function(id, cb) {
    db.get(id, returnHandler("NotFound", cb)); 
    //this will return standard 404 NotFound if error or db returns non result
}
returnHandler(error, name, cb);
returnHandler(error, cb);
  • error — can be standard http error name in camel case notation or error class. For custom error classes implementation look in the apis lib documentation;
  • name — return value name or return object. If name is string it will return {name: result}. If name is object, it will return this object. If no name provided return result;
  • cb — callback

###Errors implemented in apis

  • 400 BadRequest
  • 401 AuthRequired
  • 403 Forbidden
  • 404 NotFound
  • 405 MethodNotAllowed
  • 409 Conflict
  • 413 RequestEntityTooLarge
  • 415 UnsupportedMediaType
  • 500 ServerError

Keywords

FAQs

Package last updated on 02 Oct 2015

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

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc