首页 > 解决方案 > 在 Redux-Saga 中使用 POST 调用处理错误

问题描述

如果错误是内部服务器(代码:500),我的 API 将返回 JSON 作为响应。下面是我正在使用的代码。我能够收到错误(错误 500:内部服务器错误),但似乎无法在响应中获得 JSON。请帮忙。

    try{
    const items = yield call(request, url, postOptions);
    if (items.status >= 200 && items.status < 300) {
      const jsonResponse = yield items.text()
      yield put(itemsLoaded(jsonResponse))
    }
    else throw items; 

  } catch (err) {
    yield put(itemsLoadingError(err));
  }

标签: posterror-handlingreact-reduxredux-sagayield

解决方案


推荐阅读