refactor: Add type annotations for response objects in API request handling
This commit is contained in:
@@ -19,12 +19,16 @@ export class DiscordRateLimiter {
|
||||
public async request<T>(path: string, options: RequestInit = {}): Promise<T> {
|
||||
const url = `${this.baseUrl}${path}`;
|
||||
|
||||
const headers = {
|
||||
const headers: Record<string, string> = {
|
||||
'Authorization': `Bot ${this.botToken}`,
|
||||
'Content-Type': 'application/json',
|
||||
...options.headers,
|
||||
...(options.headers as Record<string, string>),
|
||||
};
|
||||
|
||||
// Only set Content-Type to application/json if body is a string and not explicitly set
|
||||
if (typeof options.body === 'string' && !('Content-Type' in headers)) {
|
||||
headers['Content-Type'] = 'application/json';
|
||||
}
|
||||
|
||||
const response = await fetch(url, { ...options, headers });
|
||||
|
||||
if (response.status === 429) {
|
||||
|
||||
Reference in New Issue
Block a user