Git Product home page Git Product logo

Comments (7)

dougwilson avatar dougwilson commented on June 26, 2024

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.

dougwilson avatar dougwilson commented on June 26, 2024

@Jokero any interest in making a PR for this?

from http-errors.

Jokero avatar Jokero commented on June 26, 2024

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.

dougwilson avatar dougwilson commented on June 26, 2024

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.

jonathanong avatar jonathanong commented on June 26, 2024

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.

Jokero avatar Jokero commented on June 26, 2024

@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.

dougwilson avatar dougwilson commented on June 26, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.