From d4fd0d9d6ba3c07cb4813c802710d01bd3da42de Mon Sep 17 00:00:00 2001 From: Johan le stickman Date: Sun, 22 Oct 2023 12:18:13 +0200 Subject: [PATCH] fetch with 7s timeout --- index.js | 6 ++++++ package.json | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index a1b4874..b2aa7cf 100644 --- a/index.js +++ b/index.js @@ -197,9 +197,15 @@ async function fetch(_options){ if(this.options.verbose) console.info("Added token to request:", this.sessionToken) } + // Définir un controller pour pouvoir timeout la requête + var controller = new AbortController() + if(!options.signal) options.signal = controller.signal + var controllerTimeout = setTimeout(() => controller.abort(), 7000) + // Faire la requête var response = await _fetch(url, options).catch(() => {}) if(this.options.verbose) console.info("Fetched:", response.status, response.statusText) + clearTimeout(controllerTimeout) // On enlève le timeout // Si la requête a échoué if(!response?.ok){ diff --git a/package.json b/package.json index 2750ba3..99e88e4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "freebox-wrapper", - "version": "1.0.3", + "version": "1.0.4", "description": "Un wrapper pour l'API de Freebox OS, gère la connexion et facilite les requêtes.", "main": "index.js", "keywords": [