vuex-saga icon indicating copy to clipboard operation
vuex-saga copied to clipboard

How can I handle Error?

Open phuocnt0612 opened this issue 7 years ago • 3 comments

* 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

phuocnt0612 avatar Sep 24 '17 05:09 phuocnt0612

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 avatar Sep 24 '17 09:09 BosNaufal

@BosNaufal The same. It doesn't move to catch block. P/s: api.auth.login is returning a Promise (using axios)

phuocnt0612 avatar Sep 24 '17 13:09 phuocnt0612

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

BosNaufal avatar Oct 03 '17 00:10 BosNaufal