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

Error message is not accessible #137

Open
dipapazacharias opened this issue Dec 28, 2021 · 1 comment
Open

Error message is not accessible #137

dipapazacharias opened this issue Dec 28, 2021 · 1 comment

Comments

@dipapazacharias
Copy link

I do a request to an API which throws errors in specific scenarios. The error reaches the browser as it should. The request's response on the browser's devtools is:

errors: [{message: "Account with provided email already exists", type: "ValidationError"}]

But when I do console.log(JSON.stringify(e, null, 2)) in the try catch block, I get:

{ "name": "StatusError", "statusCode": 422, "res": { "statusCode": 422 }, "headers": { "content-length": "111", "content-type": "application/json; charset=utf-8" } }

There is no message in the error object.

@samuelmr
Copy link

Looking at https://github.com/mikeal/bent/blob/master/src/nodejs.js#L55 there is e.text but it's not a property but a method.

Try something like console.log(e.statusCode + ' ' + e.message + ' (' + await e.text() + ')')

There is also e.json() which you can await and JSON.stringify().

This should probably be documented.

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

2 participants