Skip to content
This repository has been archived by the owner on Jan 8, 2022. It is now read-only.

Commit

Permalink
fix(Rest): lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
iCrawl committed Dec 8, 2021
1 parent adb5302 commit 53c0cce
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
6 changes: 3 additions & 3 deletions packages/rest/__tests__/REST.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ test('Request and Response Events', async () => {
route: '/request',
data: { attachments: undefined, body: undefined },
retries: 0,
}),
}) as APIRequest,
);
expect(responseListener).toHaveBeenLastCalledWith<[APIRequest, Response]>(
expect.objectContaining({
Expand All @@ -234,8 +234,8 @@ test('Request and Response Events', async () => {
route: '/request',
data: { attachments: undefined, body: undefined },
retries: 0,
}),
expect.objectContaining({ status: 200, statusText: 'OK' }),
}) as APIRequest,
expect.objectContaining({ status: 200, statusText: 'OK' }) as Response,
);

api.off('request', requestListener);
Expand Down
6 changes: 4 additions & 2 deletions packages/rest/__tests__/RequestHandler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ nock(`${DefaultRestOptions.api}/v${DefaultRestOptions.version}`)
})
.get('/regularRequest')
.reply(204, { test: true })
.patch('/channels/:id', (body) => ['name', 'topic'].some((key) => Reflect.has(body, key)))
.patch('/channels/:id', (body) => ['name', 'topic'].some((key) => Reflect.has(body as Record<string, unknown>, key)))
.reply(function handler(): nock.ReplyFnResult {
sublimitHits += 1;
sublimitRequests += 1;
Expand Down Expand Up @@ -110,7 +110,9 @@ nock(`${DefaultRestOptions.api}/v${DefaultRestOptions.version}`)
},
];
})
.patch('/channels/:id', (body) => ['name', 'topic'].every((key) => !Reflect.has(body, key)))
.patch('/channels/:id', (body) =>
['name', 'topic'].every((key) => !Reflect.has(body as Record<string, unknown>, key)),
)
.reply(function handler(): nock.ReplyFnResult {
sublimitRequests += 1;
const response = 10 - sublimitRequests >= 0 ? 204 : 429;
Expand Down
4 changes: 3 additions & 1 deletion packages/rest/src/lib/RequestManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,9 @@ export class RequestManager extends EventEmitter {
// eslint-disable-next-line no-eq-null
if (request.body != null) {
if (request.appendToFormData) {
for (const [key, value] of Object.entries(request.body as any)) formData.append(key, value);
for (const [key, value] of Object.entries(request.body as Record<string, unknown>)) {
formData.append(key, value);
}
} else {
formData.append('payload_json', JSON.stringify(request.body));
}
Expand Down
10 changes: 6 additions & 4 deletions packages/rest/src/lib/errors/DiscordAPIError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ export interface RequestBody {
json: unknown | undefined;
}

function isErrorGroupWrapper(error: any): error is DiscordErrorGroupWrapper {
return Reflect.has(error, '_errors');
function isErrorGroupWrapper(error: DiscordError): error is DiscordErrorGroupWrapper {
return Reflect.has(error as Record<string, unknown>, '_errors');
}

function isErrorResponse(error: any): error is DiscordErrorFieldInformation {
return typeof Reflect.get(error, 'message') === 'string';
function isErrorResponse(error: DiscordError): error is DiscordErrorFieldInformation {
return typeof Reflect.get(error as Record<string, unknown>, 'message') === 'string';
}

/**
Expand Down Expand Up @@ -85,11 +85,13 @@ export class DiscordAPIError extends Error {

if (typeof v === 'string') {
yield v;
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
} else if (isErrorGroupWrapper(v)) {
for (const error of v._errors) {
yield* this.flattenDiscordError(error, nextKey);
}
} else {
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
yield* this.flattenDiscordError(v, nextKey);
}
}
Expand Down

0 comments on commit 53c0cce

Please sign in to comment.