Comments (7)
As far as I know, this is the way JavaScript itself works (try running JSON.stringify(new Error('oops!')))
. If you would like to fix this, please feel free to make a PR :)
from http-errors.
@Jokero any interest in making a PR for this?
from http-errors.
I want to make a PR in the future to completely update this module. https://github.com/Jokero/http-error/blob/master/index.js
from http-errors.
Ok, @Jokero , though this module's interface is part of Koa, so any major changes please make sure you discuss with the Koa project first.
from http-errors.
i'm 👍 to making everything stringify-able, particularly err.message
and err.code
(i think it was code that couldn't be stringified...)
here's of an example of us hacking around it: https://github.com/stream-utils/raw-body/blob/1e45346682da648ab02e5c92577de10caab905ac/index.js#L167
i don't see how this would break backwards incompatibility, but we could just add it to koa v2
from http-errors.
@jonathanong As workaround I created separate npm module https://github.com/Jokero/http-error-constructor
Every property instead of statusCode
, status
and name
is stringified. I excluded statusCode
and status
because you can always get it from response without any additional field in error body.
It's possible to create error with custom status code (there is http-errors
issue for it). I use real constructors instead of error factories, so additionally you can do like this:
var err = new HttpError.BadRequest();
console.log(err instanceof HttpError); // true
console.log(err instanceof HttpError.BadRequest); // true
It fixes another issue.
from http-errors.
@jonathanong what do you think if we just added a toJSON
method to the root prototype that would understand how to serialize all the properties (especially the non-own properties like statusCode
)? It could potentially implement the .expose
logic in the serialization, but not sure if that's a good idea or not.
from http-errors.
Related Issues (20)
- Include typescript typings in the package
- Cannot subclass errors HOT 1
- How to use error constructors directly HOT 13
- instanceof HttpError not working when receiving error from other package HOT 7
- Cannot install package due to flatmap-stream dependency HOT 2
- The second argument "Error" overwrites the first argument "status" HOT 2
- Feature Request: Ability to attach custom properties to named errors HOT 4
- Always returning status code 500 HOT 1
- [Feature Request] Support "errors" inside properties HOT 3
- support new createError.BadRequest(obj) HOT 2
- Create release for new `isHttpError` HOT 6
- Guard Error.captureStackTrace() HOT 2
- Question: Support "errors" inside properties HOT 1
- Add "expose" to "new createError.[code || name]([msg]))" syntax HOT 1
- Support for Error.cause HOT 3
- populateConstructorExports calls toIdentifier with unknown HOT 13
- A low-level question HOT 2
- httpError(N, error) is misleading if error is already an HTTP error HOT 2
- Migrate to ES6 classes HOT 2
- Allow HttpError extension by ES6 classes HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from http-errors.