mirror of
https://github.com/tale/headplane.git
synced 2026-08-22 18:56:38 +00:00
feat: improve error returning and parsing logic
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user