endpoint-handler
v2.0.3
Published
Express error and response handler when using Promises
Downloads
1,202
Readme
endpoint-handler
Express error and response handler when using Promises.
install
npm install endpoint-handler --save
usage
express = require("express")
controller = require("./controller")
router = express.Router()
{ route } = require("endpoint-handler") router
# router.use <<middleware>>
route.get "/", controller.get
route.put "/", controller.update
module.exports = router
features
- if you return a successful
Promise
, it responds a 200 code with the json. - if you return a rejected
Promise
, it responds a 500 code with the error. - if you return a
Promise
that fails with an object{ statusCode, body }
, it responds astatusCode
code with thebody
. - if you return a no-thenable, you are turning off the endpoint handler.