2.0.3 • Published 6 years ago
endpoint-handler v2.0.3
endpoint-handler
Express error and response handler when using Promises.
install
npm install endpoint-handler --saveusage
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 = routerfeatures
- 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
Promisethat fails with an object{ statusCode, body }, it responds astatusCodecode with thebody. - if you return a no-thenable, you are turning off the endpoint handler.