From 97231d29d3038774a8c5620b91a3214321e6e66c Mon Sep 17 00:00:00 2001 From: RemixDev Date: Tue, 7 Dec 2021 12:01:08 +0100 Subject: [PATCH] Fixed recursion in api calls --- deezer/api.js | 6 ++++-- deezer/gw.js | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/deezer/api.js b/deezer/api.js index 6b0b6df..a1ba2d1 100644 --- a/deezer/api.js +++ b/deezer/api.js @@ -49,8 +49,10 @@ class API{ }).json() } catch (e) { console.debug("[ERROR] deezer.api", method, args, e.name, e.message) - // await new Promise(r => setTimeout(r, 2000)) // sleep(2000ms) - // return this.api_call(method, args) + if (["ECONNABORTED", "ECONNREFUSED", "ECONNRESET", "ENETRESET", "ETIMEDOUT"].includes(e.code)){ + await new Promise(r => setTimeout(r, 2000)) // sleep(2000ms) + return this.api_call(method, args) + } throw new APIError(`${method} ${args}:: ${e.name}: ${e.message}`) } if (result_json.error){ diff --git a/deezer/gw.js b/deezer/gw.js index 2fcb09a..de8970c 100644 --- a/deezer/gw.js +++ b/deezer/gw.js @@ -64,8 +64,10 @@ class GW{ }).json() }catch (e){ console.debug("[ERROR] deezer.gw", method, args, e.name, e.message) - // await new Promise(r => setTimeout(r, 2000)) // sleep(2000ms) - // return this.api_call(method, args, params) + if (["ECONNABORTED", "ECONNREFUSED", "ECONNRESET", "ENETRESET", "ETIMEDOUT"].includes(e.code)){ + await new Promise(r => setTimeout(r, 2000)) // sleep(2000ms) + return this.api_call(method, args) + } throw new GWAPIError(`${method} ${args}:: ${e.name}: ${e.message}`) } if (result_json.error.length) throw new GWAPIError(result_json.error)