Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible improvement on errorResponder #138

Open
itarizin opened this issue Aug 3, 2020 · 0 comments
Open

Possible improvement on errorResponder #138

itarizin opened this issue Aug 3, 2020 · 0 comments

Comments

@itarizin
Copy link

itarizin commented Aug 3, 2020

Hi @kimmobrunfeldt , first of all thank you very much for your work.
I noticed that the error response was not homogeneous, when it comes to errors from Puppeteer.
To trigger a "managed" error:
{ output: "screenshot", screenshot: { type: "ABC", ... }
This will return a json with error code, message, error list etc..

To trigger an "unmanaged" error:
{ output: "screenshot", screenshot: { type: "png", fullPage: true, clip: { 0, 0, 32, 32 } }
This will return only a status 500 and message of "Internal server error"

I've changed it for my deployment, and maybe the idea might be implemented on your side, if you consider it.
The chance will make the ErrorResponder send back always a json with the same schema even when there's a "unhandled" error (like in the example.

Here's my code for "errorResponder" in src\middleware\error-responder.js

  return function errorResponder(err, req, res, next) {
    const status = err.status ? err.status : 480;
    var httpMessage = http.STATUS_CODES[status];
    httpMessage = httpMessage ? httpMessage : err.message;

    const errBody = _.has(err, 'errors')
      ? err.errors
      : [{fields: [], location: "body", messages:[err.message]}];

    res.status(status);
    res.send({ status, statusText: httpMessage, errors: errBody });
  };

Thanks, cheers
Andy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant