我的API状态404有两个消息(store not found
和user 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 2
和throw the error
API情况为user not found
时,无法输入throw the error
任何帮助将不胜感激。