feat: improve error returning and parsing logic

This commit is contained in:
Aarnav Tale
2025-04-03 03:00:38 -04:00
parent 234020eec5
commit 6a94e815f2
7 changed files with 56 additions and 38 deletions
+1 -14
View File
@@ -1,6 +1,7 @@
import { readFile } from 'node:fs/promises';
import { Agent, Dispatcher, request } from 'undici';
import log from '~/utils/log';
import ResponseError from './api-error';
export async function createApiClient(base: string, certPath?: string) {
if (!certPath) {
@@ -20,20 +21,6 @@ export async function createApiClient(base: string, certPath?: string) {
}
}
// Represents an error that occurred during a response
// Thrown when status codes are >= 400
export class ResponseError extends Error {
status: number;
response: string;
constructor(status: number, response: string) {
super(`Response Error (${status}): ${response}`);
this.name = 'ResponseError';
this.status = status;
this.response = response;
}
}
export class ApiClient {
private agent: Agent;
private base: string;