summaryrefslogtreecommitdiff
path: root/packages/misskey-js/src/api.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/misskey-js/src/api.ts')
-rw-r--r--packages/misskey-js/src/api.ts9
1 files changed, 7 insertions, 2 deletions
diff --git a/packages/misskey-js/src/api.ts b/packages/misskey-js/src/api.ts
index ea1df57f3d..659a29a221 100644
--- a/packages/misskey-js/src/api.ts
+++ b/packages/misskey-js/src/api.ts
@@ -56,6 +56,10 @@ export class APIClient {
return obj !== null && typeof obj === 'object' && !Array.isArray(obj);
}
+ private assertSpecialEpReqType(ep: keyof Endpoints): ep is keyof typeof endpointReqTypes {
+ return ep in endpointReqTypes;
+ }
+
public request<E extends keyof Endpoints, P extends Endpoints[E]['req']>(
endpoint: E,
params: P = {} as P,
@@ -63,9 +67,10 @@ export class APIClient {
): Promise<SwitchCaseResponseType<E, P>> {
return new Promise((resolve, reject) => {
let mediaType = 'application/json';
- if (endpoint in endpointReqTypes) {
+ if (this.assertSpecialEpReqType(endpoint) && endpointReqTypes[endpoint] != null) {
mediaType = endpointReqTypes[endpoint];
}
+
let payload: FormData | string = '{}';
if (mediaType === 'application/json') {
@@ -100,7 +105,7 @@ export class APIClient {
method: 'POST',
body: payload,
headers: {
- 'Content-Type': endpointReqTypes[endpoint],
+ 'Content-Type': mediaType,
},
credentials: 'omit',
cache: 'no-cache',