国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

axios-retry插件-axios請求失敗自動重試

這篇具有很好參考價值的文章主要介紹了axios-retry插件-axios請求失敗自動重試。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

介紹

axios-retry 對外導出 axiosRetry() 方法: 通過對 axios 單例添加“攔截器”,來擴展實現(xiàn)自動重試網(wǎng)絡請求功能。

安裝

npm install axios-retry

使用

// CommonJS
// const axiosRetry = require('axios-retry');

// ES6
import axiosRetry from 'axios-retry';

axiosRetry(axios, { retries: 3 });

axios.get('http://example.com/test') // The first request fails and the second returns 'ok'
  .then(result => {
    result.data; // 'ok'
  });

// Exponential back-off retry delay between requests
axiosRetry(axios, { retryDelay: axiosRetry.exponentialDelay});

// Custom retry delay
axiosRetry(axios, { retryDelay: (retryCount) => {
  return retryCount * 1000;
}});

// 自定義 axios 實例
const client = axios.create({ baseURL: 'http://example.com' });
axiosRetry(client, { retries: 3 });

client.get('/test') // 第一次請求失敗,第二次成功
  .then(result => {
    result.data; // 'ok'
  });

// 允許 request-specific 配置
client
  .get('/test', {
    'axios-retry': {
      retries: 0
    }
  })
  .catch(error => { // The first request fails
    error !== undefined
  });

備注:?除非?shouldResetTimeout被設置, 這個插件
將請求超時解釋為全局值, 不是針對每一個請求,二是全局的設置

配置

Name Type Default Description
retries Number 3 The number of times to retry before failing.
retryCondition Function isNetworkOrIdempotentRequestError 如果應該重試請求,則進一步控制的回調(diào)。默認情況下,如果是冪等請求的網(wǎng)絡錯誤或5xx錯誤,它會重試(GET, HEAD, OPTIONS, PUT or DELETE).
shouldResetTimeout Boolean false Defines if the timeout should be reset between retries
retryDelay Function function noDelay() { return 0; } 控制重試請求之間的延遲。默認情況下,重試之間沒有延遲。另一個選項是exponentialDelay (Exponential Backoff). The function is passed?retryCount?and?error.

測試

克隆這個倉庫 然后 執(zhí)行:

npm test

axios-retry

Axios plugin that intercepts failed requests and retries them whenever possible.

Installation

npm install axios-retry

Usage

// CommonJS
// const axiosRetry = require('axios-retry');

// ES6
import axiosRetry from 'axios-retry';

axiosRetry(axios, { retries: 3 });

axios.get('http://example.com/test') // The first request fails and the second returns 'ok'
  .then(result => {
    result.data; // 'ok'
  });

// Exponential back-off retry delay between requests
axiosRetry(axios, { retryDelay: axiosRetry.exponentialDelay });

// Custom retry delay
axiosRetry(axios, { retryDelay: (retryCount) => {
  return retryCount * 1000;
}});

// Works with custom axios instances
const client = axios.create({ baseURL: 'http://example.com' });
axiosRetry(client, { retries: 3 });

client.get('/test') // The first request fails and the second returns 'ok'
  .then(result => {
    result.data; // 'ok'
  });

// Allows request-specific configuration
client
  .get('/test', {
    'axios-retry': {
      retries: 0
    }
  })
  .catch(error => { // The first request fails
    error !== undefined
  });

Note:?Unless?shouldResetTimeout?is set, the plugin interprets the request timeout as a global value, so it is not used for each retry but for the whole request lifecycle.

Options

Name Type Default Description
retries Number 3 The number of times to retry before failing. 1 = One retry after first failure
retryCondition Function isNetworkOrIdempotentRequestError A callback to further control if a request should be retried. By default, it retries if it is a network error or a 5xx error on an idempotent request (GET, HEAD, OPTIONS, PUT or DELETE).
shouldResetTimeout Boolean false Defines if the timeout should be reset between retries
retryDelay Function function noDelay() { return 0; } A callback to further control the delay in milliseconds between retried requests. By default there is no delay between retries. Another option is exponentialDelay (Exponential Backoff). The function is passed?retryCount?and?error.
onRetry Function function onRetry(retryCount, error, requestConfig) { return; } A callback to notify when a retry is about to occur. Useful for tracing. By default nothing will occur. The function is passed?retryCount,?error, and?requestConfig.

Testing

Clone the repository and execute:

npm test

?文章來源地址http://www.zghlxwxcb.cn/news/detail-496158.html

到了這里,關于axios-retry插件-axios請求失敗自動重試的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權(quán),不承擔相關法律責任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實不符,請點擊違法舉報進行投訴反饋,一經(jīng)查實,立即刪除!

領支付寶紅包贊助服務器費用

相關文章

  • Axios請求失敗重刷接口

    Axios請求失敗重刷接口

    頁面接口請求時偶爾會出現(xiàn) Network Error 異常報錯,重新請求就會請求成功 接口沒辦法捕獲異常原因,前端來做一次重刷解決問題 net::ERR_SSL_PROTOCOL_ERROR net::ERR_CONNECTION_REFUSED 記錄請求map(以url為唯一標識),并設置單個接口重刷最大次數(shù) 格式:{ ‘https://xxxx/xxx?id=1’, 0 } 請求成

    2024年02月07日
    瀏覽(18)
  • 關于自動化測試用例失敗重試的一些思考

    關于自動化測試用例失敗重試的一些思考

    自動化測試用例失敗重跑有助于提高自動化用例的穩(wěn)定性,那我們來看一下,python和java生態(tài)里都有哪些具體做法? 如果是在python生態(tài)里,用pytest做測試驅(qū)動,那么可以通過pytest的插件pytest-rerunfailures來實現(xiàn)失敗用例重跑,具體的使用方式有兩種,一種是通過命令行指定pytes

    2024年02月14日
    瀏覽(18)
  • 重試框架入門:Spring-Retry&Guava-Retry

    重試框架入門:Spring-Retry&Guava-Retry

    在日常工作中,隨著業(yè)務日漸龐大,不可避免的涉及到調(diào)用遠程服務,但是遠程服務的健壯性和網(wǎng)絡穩(wěn)定性都是不可控因素,因此,我們需要考慮合適的重試機制去處理這些問題,最基礎的方式就是手動重試,侵入業(yè)務代碼去處理,再高端一點的通過切面去處理,較為優(yōu)雅的

    2024年02月13日
    瀏覽(57)
  • rabbitmq:retry重試機制和延遲消息的實現(xiàn)

    rabbitmq:retry重試機制和延遲消息的實現(xiàn)

    rabbitmq:retry重試機制和延遲消息的實現(xiàn) 在消費者消費消息的時候可能會因為網(wǎng)絡等外部原因?qū)е孪⑻幚硎?,這個時候如果將消息直接丟棄會導致正常的業(yè)務丟失,但是如果是一條本身就有問題的消息,那么這個時候又必須丟棄掉,如果選擇用channel.basicNack 或 channel.basi

    2024年02月13日
    瀏覽(20)
  • Java 重試框架 Spring-Retry | 快速入門

    ?? 本節(jié)目標:了解傳統(tǒng)重試的寫法以及 Spring-Retry 快速入門。 下面使用一個例子來講述:調(diào)用第三方接口獲取數(shù)據(jù),支持重試 3 次,每次重試間隔 5 秒。 傳統(tǒng)寫法 :while 循環(huán),判斷是否有異常,有異常則重試,并使用 Thread 延遲,直到重試次數(shù)用完或重試成功為止。 調(diào)用第

    2024年04月10日
    瀏覽(19)
  • 基于 Guava Retry 在Spring封裝一個重試功能

    pom依賴 注解類 測試類

    2024年02月13日
    瀏覽(19)
  • Spring-retry 優(yōu)雅的實現(xiàn)循環(huán)重試功能

    Spring-retry 優(yōu)雅的實現(xiàn)循環(huán)重試功能

    引言 ? ? ?在實際的應用場景中,可能經(jīng)常會遇到,當請求一個接口調(diào)一個服務的時候,出現(xiàn)異常或網(wǎng)絡出現(xiàn)故障的情況下就會失敗,而對于那些重要的服務當失敗后,可能我們就會進行重試,多調(diào)用幾次,如果還是失敗再另外進行單獨處理。接下來,就是要講解的重點內(nèi)容

    2024年02月12日
    瀏覽(14)
  • VUE項目使用axios發(fā)送post跨域請求,返回數(shù)據(jù)失敗問題

    Access to XMLHttpRequest at \\\'http://xxxx\\\' from origin \\\'http://localhost:8080\\\' has been blocked by CORS policy: Response to preflight request doesn\\\'t pass access control check: No \\\'Access-Control-Allow-Origin\\\' header is present on the requested resource. 第一步 ,在后端接受方,對返回的數(shù)據(jù)添加 響應頭 ,使用下面這句代碼: 第二步

    2024年02月11日
    瀏覽(25)
  • 小程序支付報錯:向微信請求統(tǒng)一下單失敗:商戶號該產(chǎn)品權(quán)限未開通,請前往商戶平臺>產(chǎn)品中心檢查后重試

    小程序支付報錯:向微信請求統(tǒng)一下單失敗:商戶號該產(chǎn)品權(quán)限未開通,請前往商戶平臺>產(chǎn)品中心檢查后重試

    一.檢查微信商戶和小程序是否建立綁定關系,沒有綁定的需要進行綁定 1.登錄微信商戶平臺,產(chǎn)品中心--AppId賬號管理--關聯(lián)AppId 2.填寫要綁定的小程序AppId和認證主體點提交(可在微信公眾平臺--設置--基本設置獲取) 3.登錄微信公眾平臺 --功能--微信支付--待關聯(lián)商戶號--綁定 ?二

    2024年02月11日
    瀏覽(38)
  • 分布式重試服務平臺 Easy-Retry

    分布式重試服務平臺 Easy-Retry

    ??在介紹這款開源產(chǎn)品前先給大家介紹一個開源組織:aizuda–愛組搭 ??可以看到Easy-Retry就是愛組搭的開源項目之一。 ??在分布式系統(tǒng)大行其道的當前,系統(tǒng)數(shù)據(jù)的準確性和正確性是重大的挑戰(zhàn),基于CAP理論,采用柔性事務,保障系統(tǒng)可用性以及數(shù)據(jù)的最終一致性成為

    2024年02月09日
    瀏覽(22)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領取紅包,優(yōu)惠每天領

二維碼1

領取紅包

二維碼2

領紅包