post - 在 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));
}
解决方案
推荐阅读
- python - 预期 inception_v3_input 有 4 个维度,但得到了形状为 (5700, 19321) 的数组
- c# - 从 C# 中的特定多维数组中提取列
- eclipse - glassfish 5 JSF2.2 & CDI 部署失败
- kubernetes - CI/CD 的 Helm 图表版本
- c# - MQ 错误原因:在 C# .NET 客户端正常工作多天后随机开始出现 2058
- php - laravel 路由中找不到页面错误
- javascript - 如何将每个用户路由/链接到他们自己的数据?
- docker - docker toolbox - 无法使用 docker-compose 挂载目录
- java - 线程“主”java.lang.IndexOutOfBoundsException 中的异常:
- php - 如何使密码验证功能与 $_POST 一起使用