JS-DevTools / ono

Wrap errors without losing the original message, stack trace, or properties
https://jstools.dev/ono/
MIT License
106 stars 11 forks source link

Oh No! HTTP => require('ono/http'); #3

Closed danieljoppi closed 6 years ago

danieljoppi commented 7 years ago

Suggestion to issue #2

const ono = require('ono/http');

throw ono.badRequest('Missing ID');

output

{
  "status": 400,
  "name": "Error",
  "message": "Missing ID",
  "stack": "Error: Missing ID
    at Object.exports.(anonymous function) [as badRequest] (/ono/http/index.js:12:19)
    at repl:1:9
    at ContextifyScript.Script.runInThisContext (vm.js:44:33)
    at REPLServer.defaultEval (repl.js:239:29)
    at bound (domain.js:301:14)
    at REPLServer.runBound [as eval] (domain.js:314:12)
    at REPLServer.onLine (repl.js:440:10)
    at emitOne (events.js:120:20)
    at REPLServer.emit (events.js:210:7)"
}
coveralls commented 7 years ago

Coverage Status

Coverage remained the same at 98.058% when pulling 1dbeddd2a2ed60da9c47f6bcd96e553bad615db8 on danieljoppi:feature/http-errors into ac53fdc121cdd64ecc386ee415dcee4038216047 on BigstickCarpet:master.

JamesMessinger commented 7 years ago

I like this idea, and I think your implementation is clever too. I didn't know about the statuses package before. It's pretty cool/useful.

However, I think this should be a separate npm package (e.g. ono-http) rather than part of the main ono package.

danieljoppi commented 6 years ago

ono-http is great!