Skip to content

Commit

Permalink
fix: add type casting for json result
Browse files Browse the repository at this point in the history
  • Loading branch information
thewilloftheshadow committed Mar 9, 2023
1 parent f84dd74 commit 1f873b2
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/RequestHandler.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import fetch from "node-fetch"
import { AmariBot, AmariError, RatelimitError } from "."
import { AmariBot, AmariError, APIError, RatelimitError } from "."
export class RequestHandler {
_client: AmariBot
constructor(client: AmariBot) {
Expand All @@ -23,16 +23,16 @@ export class RequestHandler {
try {
const res = await fetch(url, options)
if (res.status >= 200 && res.status < 300) {
const json = await res.json()
const json = await res.json() as APIError
resolve(json)
if (this._client.debug) console.debug("Success: \n", json)
} else if (res.status === 429) {
const json = await res.json()
const json = await res.json() as APIError
if (this._client.debug) console.debug("Ratelimited: \n", res, json)
reject(new RatelimitError(res))
} else {
try {
const json = await res.json()
const json = await res.json() as APIError
if (this._client.debug) console.debug("API Error: \n", res, json)
reject(new AmariError(res, json))
} catch (err) {
Expand Down

0 comments on commit 1f873b2

Please sign in to comment.