get properly handled with request manager

This commit is contained in:
Skillz
2020-05-16 09:55:25 -04:00
parent 706c7c2cd3
commit c9b901cdc0
4 changed files with 6 additions and 10 deletions
+1
View File
@@ -1,5 +1,6 @@
{
"deno.enable": true,
"editor.formatOnSave": true,
"deno.autoFmtOnSave": true,
"deno.unstable": true
}
+1 -1
View File
@@ -33,7 +33,7 @@ export const createClient = async (data: ClientOptions) => {
authorization = `Bot ${data.token}`;
// Initial API connection to get info about bots connection
botGatewayData = await RequestManager.get(endpoints.GATEWAY_BOT);
botGatewayData = await RequestManager.get(endpoints.GATEWAY_BOT) as DiscordBotGatewayData;
identifyPayload.token = data.token;
identifyPayload.intents = data.intents.reduce(
+3 -8
View File
@@ -41,12 +41,7 @@ processRateLimitedPaths();
export const RequestManager = {
// Something off about using runMethod with get breaks when using fetch
get: async (url: string, body?: unknown) => {
await checkRatelimits(url);
const result = await fetch(url, createRequestBody(body));
handleStatusCode(result.status);
processHeaders(url, result.headers);
return result.json();
return runMethod(RequestMethod.Get, url, body)
},
post: (url: string, body?: unknown) => {
return runMethod(RequestMethod.Post, url, body);
@@ -62,7 +57,7 @@ export const RequestManager = {
},
};
function createRequestBody(body: any, method?: RequestMethod) {
function createRequestBody(body: any, method: RequestMethod) {
return {
headers: {
Authorization: authorization,
@@ -72,7 +67,7 @@ function createRequestBody(body: any, method?: RequestMethod) {
"X-Audit-Log-Reason": body ? encodeURIComponent(body.reason) : "",
},
body: JSON.stringify(body),
method: method?.toUpperCase(),
method: method.toUpperCase(),
};
}
+1 -1
View File
@@ -59,7 +59,7 @@ export function createChannel(data: ChannelCreatePayload) {
}
const result = await RequestManager.get(
endpoints.CHANNEL_MESSAGE(data.id, id),
);
) as MessageCreateOptions;
return createMessage(result);
},
/** Fetches between 2-100 messages. Requires VIEW_CHANNEL and READ_MESSAGE_HISTORY */