vuex-saga
vuex-saga copied to clipboard
How can I handle Error?
* login (ctx, {email, password}) {
try {
return yield call(api.auth.login, {email, password})
} catch (e) {
console.log(e)
}
}
I try to handle like this but no success
Hi @phuocnt0612, Thank you for giving me an issue. Would you like to try to remove the return statement, and return it after try an catch.
login (ctx, {email, password}) {
let response = false
try {
response = yield call(api.auth.login, {email, password})
} catch (e) {
console.log(e)
response = e
}
return response
}
@BosNaufal
The same. It doesn't move to catch
block.
P/s: api.auth.login
is returning a Promise (using axios)
@phuocnt0612 I think it's a bug, for now you can use conventional way like
login (ctx, {email, password}) {
let response = false
response = yield call(api.auth.login, {email, password})
if (response.status === 200) {
// success here
} else {
// error here
}
return response
}