RxJS抛出错误显示未处理的JS异常

时间:2019-09-04 08:18:33

标签: react-native rxjs

我的API状态404有两个消息(store not founduser not found

store not found出现RxJS抛出错误时,但user not found显示Unhandled JS Exception

我不知道为什么会发生这个问题。

这是我的API设置:

import Rx from 'rxjs/Rx';

handleError(error) {
    console.log('start check')
    console.log('error =>', error)
    console.log('error.response =>', error.response)
    console.log('error request =>', error.request)
    if (error.response) {
      if (error.response.status === 200) {
        console.log('1')
        return Rx.Observable.of(error.response)
      } else {
        console.log('2')
        console.log('error', error.response)
        return Rx.Observable.throw(error.response)
      }
    } else if (error.request) {
      // The request was made but no response was received
      // `error.request` is an instance of XMLHttpRequest in the browser and an instance of
      // http.ClientRequest in node.js
      // Toast.show(error.request._response)
      console.log(error.request)
      return Rx.Observable.empty()
    } else {
      // Something happened in setting up the request that triggered an Error
      console.log('Error', error.message)
      return Rx.Observable.empty()
    }
    console.log(error.config)

  }

订阅:

StoreService.shared.getStoreInfo().subscribe((response) => {
      const { status } = response
      // success logic
    },(error) => {
      console.log('throw the error ============', error)
      const { status } = error

      if (status === 403) {
        // 403 logic
      }

      if (status === 404 && error.data.message === 'store not found') {
        // store not found logic
      }

      if (status === 404 && error.data.message === 'user not found') {
        // user not found logic
      }
    })

当API情况为store not found时,我可以看到console.log 2throw the error

enter image description here

API情况为user not found时,无法输入throw the error

enter image description here

任何帮助将不胜感激。

0 个答案:

没有答案