Remove recursion in api calls

This commit is contained in:
RemixDev 2021-11-03 15:17:45 +01:00
parent 626027d5bc
commit 9aba730464
2 changed files with 9 additions and 7 deletions

View file

@ -48,9 +48,10 @@ class API{
timeout: 30000
}).json()
} catch (e) {
console.debug("[ERROR] deezer.api", method, args, e.message)
await new Promise(r => setTimeout(r, 2000)) // sleep(2000ms)
return this.api_call(method, args)
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)
throw new APIError(`${method} ${args}:: ${e.name}: ${e.message}`)
}
if (result_json.error){
if (result_json.error.code){
@ -67,7 +68,7 @@ class API{
if (result_json.error.code == 800) throw new DataException(`DataException: ${method} ${result_json.error.message || ""}`)
if (result_json.error.code == 901) throw new IndividualAccountChangedNotAllowedException(`IndividualAccountChangedNotAllowedException: ${method} ${result_json.error.message || ""}`)
}
throw APIError(result_json.error)
throw new APIError(result_json.error)
}
return result_json
}

View file

@ -63,9 +63,10 @@ class GW{
timeout: 30000
}).json()
}catch (e){
console.debug("[ERROR] deezer.gw", method, args, e.message)
await new Promise(r => setTimeout(r, 2000)) // sleep(2000ms)
return this.api_call(method, args, params)
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)
throw new GWAPIError(`${method} ${args}:: ${e.name}: ${e.message}`)
}
if (result_json.error.length) throw new GWAPIError(result_json.error)
return result_json.results