Fixed recursion in api calls

This commit is contained in:
RemixDev 2021-12-07 12:01:08 +01:00
parent ad5e45f72e
commit 97231d29d3
2 changed files with 8 additions and 4 deletions

View file

@ -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){

View file

@ -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)