mirror of
https://github.com/vkaelin/LeagueStats.git
synced 2026-03-26 13:27:28 +00:00
40 lines
959 B
JavaScript
40 lines
959 B
JavaScript
class JaxRequest {
|
|
constructor(config, endpoint, limiter) {
|
|
this.config = config
|
|
this.endpoint = endpoint
|
|
this.limiter = limiter
|
|
this.retries = config.requestOptions.retriesBeforeAbort
|
|
}
|
|
|
|
async execute() {
|
|
try {
|
|
const resp = await this.limiter.executing({
|
|
url: `https://${this.config.region}.api.riotgames.com/lol/${this.endpoint}`,
|
|
token: this.config.key,
|
|
resolveWithFullResponse: false
|
|
})
|
|
|
|
return JSON.parse(resp)
|
|
|
|
} catch ({ statusCode, ...rest }) {
|
|
this.retries--
|
|
|
|
if (statusCode !== 503 && statusCode !== 500) return
|
|
|
|
console.log('====================================')
|
|
console.log(statusCode)
|
|
console.log('====================================')
|
|
|
|
if (this.retries > 0) {
|
|
return setTimeout(
|
|
() => this.execute(),
|
|
this.config.requestOptions.delayBeforeRetry,
|
|
)
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
module.exports = JaxRequest
|