BosNaufal / vuex-saga

Better Vuex Action To Simplify Your Async Flow Process And Code Testing
MIT License
159 stars 16 forks source link

How can I handle Error? #5

Open phuocnt0612 opened 7 years ago

phuocnt0612 commented 7 years ago
* 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

BosNaufal commented 7 years ago

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
  }
phuocnt0612 commented 7 years ago

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

BosNaufal commented 7 years ago

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