Closed buenyaminyilmaz closed 1 year ago
The error contains 2 extra items, response
& data
.
I would handle the server error like this
try {
const response = await registerApi.post({
email: this.email,
password: this.password,
passwordConfirmed: this.passwordRepeat,
})
resolve(response)
} catch (error) {
console.log('ServerError', await error.response.json())
reject(error)
}
Hello, I am also looking to catch the error from server
try {
await this.api.post(deviceId + '/group/' + groupId + 's');
}
catch (error) {
console.log(await error.response.json());
}
await error.response.json() - returned: Uncaught (in promise) TypeError: Failed to execute 'json' on 'Response': body stream already read
error.data
might contain the data you are after.
Thanks!
Interesting... so I get nothing back, while the response gives JSON back. Not quite sure what's going on here... Love the library btw.
@johannesronaldsson You can access to the data using: error.body
try {
const login = await api.post(apiUri, credentials);
} catch (error) {
console.error(error.body)
}
Was this issue resolved? @buenyaminyilmaz were the responses helpful
Hi there, i will just test it out. i switched to axios, because i was in hurry
I created https://github.com/posva/mande/issues/378 to track
Hi there, i am trying to use mande. Is there any way to catch the error is given from server. For an example:
registerApi
is a mande instance. The server returns for me i this case422 (Unprocessable Entity)
and an error message. So how can i show this error message?console.log('ServerError', error)
showsServerError Error: Unprocessable Entity
. Thank you in advance