Skip to content

Commit

Permalink
fetch with 7s timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
johan-perso committed Oct 22, 2023
1 parent 5a652dc commit d4fd0d9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 6 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": [
Expand Down

0 comments on commit d4fd0d9

Please sign in to comment.