Skip to content

Commit

Permalink
fix: Throw APIError instead of normal error
Browse files Browse the repository at this point in the history
  • Loading branch information
Sup3rFire committed Apr 15, 2024
1 parent 3079f2e commit 5264924
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/util/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ const packr = new Packr({
bundleStrings: true,
});

export class APIError extends Error {
public response: APIResponse;
constructor(res: APIResponse) {
super(res.error.msg);
this.response = res;
Error.captureStackTrace(this, APIError);
}
}

export default async function (
endpoint: string,
token?: string,
Expand Down Expand Up @@ -74,7 +83,7 @@ export default async function (

if (cache_) cache.set(cache_.key, { expire: cache_.expire, data: response });

if (!(await response).success) throw Error((await response).error);
if (!(await response).success) throw new APIError(await response);

return await response;
}

0 comments on commit 5264924

Please sign in to comment.