feat(#251): add optional bapi rate limit parsing to REST clients

This commit is contained in:
tiagosiebler
2023-10-30 13:47:40 +00:00
parent eb33084b7f
commit a790fcaf04
4 changed files with 93 additions and 9 deletions

View File

@@ -7,6 +7,7 @@ import {
RestClientOptions,
RestClientType,
getRestBaseUrl,
parseRateLimitHeaders,
serializeParams,
} from './requestUtils';
import { signMessage } from './node-support';
@@ -323,7 +324,17 @@ export default abstract class BaseRestClient {
return axios(options)
.then((response) => {
if (response.status == 200) {
return response.data;
const perAPIRateLimits = this.options.parseAPIRateLimits
? parseRateLimitHeaders(
response.headers,
this.options.throwOnFailedRateLimitParse === true,
)
: undefined;
return {
rateLimitApi: perAPIRateLimits,
...response.data,
};
}
throw response;