<small id='7jRTV'></small><noframes id='7jRTV'>

    <bdo id='7jRTV'></bdo><ul id='7jRTV'></ul>

  1. <tfoot id='7jRTV'></tfoot>

    <i id='7jRTV'><tr id='7jRTV'><dt id='7jRTV'><q id='7jRTV'><span id='7jRTV'><b id='7jRTV'><form id='7jRTV'><ins id='7jRTV'></ins><ul id='7jRTV'></ul><sub id='7jRTV'></sub></form><legend id='7jRTV'></legend><bdo id='7jRTV'><pre id='7jRTV'><center id='7jRTV'></center></pre></bdo></b><th id='7jRTV'></th></span></q></dt></tr></i><div id='7jRTV'><tfoot id='7jRTV'></tfoot><dl id='7jRTV'><fieldset id='7jRTV'></fieldset></dl></div>

    1. <legend id='7jRTV'><style id='7jRTV'><dir id='7jRTV'><q id='7jRTV'></q></dir></style></legend>

    2. 反应原生 fetch 不调用 then 或 catch

      时间:2023-10-02

              <bdo id='cqkl9'></bdo><ul id='cqkl9'></ul>
              <tfoot id='cqkl9'></tfoot>
            • <i id='cqkl9'><tr id='cqkl9'><dt id='cqkl9'><q id='cqkl9'><span id='cqkl9'><b id='cqkl9'><form id='cqkl9'><ins id='cqkl9'></ins><ul id='cqkl9'></ul><sub id='cqkl9'></sub></form><legend id='cqkl9'></legend><bdo id='cqkl9'><pre id='cqkl9'><center id='cqkl9'></center></pre></bdo></b><th id='cqkl9'></th></span></q></dt></tr></i><div id='cqkl9'><tfoot id='cqkl9'></tfoot><dl id='cqkl9'><fieldset id='cqkl9'></fieldset></dl></div>

              <small id='cqkl9'></small><noframes id='cqkl9'>

              <legend id='cqkl9'><style id='cqkl9'><dir id='cqkl9'><q id='cqkl9'></q></dir></style></legend>

                  <tbody id='cqkl9'></tbody>

              • 本文介绍了反应原生 fetch 不调用 then 或 catch的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我正在使用 fetch 在 react-native 中进行一些 API 调用,有时随机 fetch 不会触发对服务器的请求,并且不会调用我的 then 或 except 块.这是随机发生的,我认为可能存在竞争条件或类似情况.在这样的请求失败后,对同一 API 的请求永远不会被触发,直到我重新加载应用程序.任何想法如何追查这背后的原因.我使用的代码如下.

                I am using fetch to make some API calls in react-native, sometimes randomly the fetch does not fire requests to server and my then or except blocks are not called. This happens randomly, I think there might be a race condition or something similar. After failing requests once like this, the requests to same API never get fired till I reload the app. Any ideas how to trace reason behind this. The code I used is below.

                const host = liveBaseHost;
                const url = `${host}${route}?observer_id=${user._id}`;
                let options = Object.assign({
                        method: verb
                    }, params
                    ? {
                        body: JSON.stringify(params)
                    }
                    : null);
                options.headers = NimbusApi.headers(user)
                return fetch(url, options).then(resp => {
                    let json = resp.json();
                    if (resp.ok) {
                        return json
                    }
                    return json.then(err => {
                        throw err
                    });
                }).then(json => json);
                

                推荐答案

                Fetch 可能会抛出错误,而您尚未添加 catch 块.试试这个:

                Fetch might be throwing an error and you have not added the catch block. Try this:

                return fetch(url, options)
                  .then((resp) => {
                    if (resp.ok) {
                      return resp.json()
                        .then((responseData) => {
                          return responseData;
                        });
                    }
                    return resp.json()
                      .then((error) => {
                        return Promise.reject(error);
                      });
                  })
                  .catch(err => {/* catch the error here *

                    <legend id='fc8vx'><style id='fc8vx'><dir id='fc8vx'><q id='fc8vx'></q></dir></style></legend>

                      • <bdo id='fc8vx'></bdo><ul id='fc8vx'></ul>

                        <tfoot id='fc8vx'></tfoot>
                          <tbody id='fc8vx'></tbody>
                        <i id='fc8vx'><tr id='fc8vx'><dt id='fc8vx'><q id='fc8vx'><span id='fc8vx'><b id='fc8vx'><form id='fc8vx'><ins id='fc8vx'></ins><ul id='fc8vx'></ul><sub id='fc8vx'></sub></form><legend id='fc8vx'></legend><bdo id='fc8vx'><pre id='fc8vx'><center id='fc8vx'></center></pre></bdo></b><th id='fc8vx'></th></span></q></dt></tr></i><div id='fc8vx'><tfoot id='fc8vx'></tfoot><dl id='fc8vx'><fieldset id='fc8vx'></fieldset></dl></div>

                      • <small id='fc8vx'></small><noframes id='fc8vx'>