diff --git a/app/server/README.md b/app/server/README.md index 6cc9653..76d5b9b 100644 --- a/app/server/README.md +++ b/app/server/README.md @@ -19,6 +19,7 @@ server │ ├── schema.ts: Defines the schema for the Headplane configuration. ├── headscale/ │ ├── api-client.ts: Creates the HTTP client that talks to the Headscale API. +│ ├── api-error.ts: Contains the ResponseError definition. │ ├── config-loader.ts: Loads the Headscale configuration (if available). │ ├── config-schema.ts: Defines the schema for the Headscale configuration. ├── web/ diff --git a/app/server/headscale/api-error.ts b/app/server/headscale/api-error.ts new file mode 100644 index 0000000..bd87ee6 --- /dev/null +++ b/app/server/headscale/api-error.ts @@ -0,0 +1,19 @@ +// Represents an error that occurred during a response +// Thrown when status codes are >= 400 +export default class ResponseError extends Error { + status: number; + response: string; + responseObject?: Record; + + constructor(status: number, response: string) { + super(`Response Error (${status}): ${response}`); + this.name = 'ResponseError'; + this.status = status; + this.response = response; + + try { + // Try to parse the response as JSON to get a response object + this.responseObject = JSON.parse(response); + } catch {} + } +}