express-toss
Makes express router handlers aware of promises. Brings more clear dataflow to express handlers.
toss.method
Transforms (rq) => Promise
function to (rq, rs) => void
function for use inside Express' handlers.
resolving
var toss = express
— return value is used as response body with status 200 and adequate mime. MIME would be determined automatically by express (application/json
in case of Object
, text/html
in case of string
, learn more).
rejecting
var toss = express
— sync throws or promise rejections will convert into 500s with specific JSON body. If debug = true
body is detailed, if debug = false
it is like a simple internal-ish error.
Resp()
var toss = express
— Resp([status], [mime], body)
is applied to express' response. Resp
can be sync-returned or used inside promise.
Wrong()
var toss = // use Wrong to create protocol-level errors// Wrong(code) creates constructor for `code` errorvar NotPermitted = var NotFound = express
— Wrong(code, [options])
creates new specific error factory. Calling that factory creates error instance. This instance can be throwed/rejected or sync-returned to indicate error situation.
flow
FlowType definitions included.
license
ISC © Strider, 2017 — 2019.