mirror of
https://github.com/tale/headplane.git
synced 2026-07-27 08:08:56 +00:00
d3d7c7cc0e
This also ships with a better error page
58 lines
1.4 KiB
TypeScript
58 lines
1.4 KiB
TypeScript
import type { HeadscaleConnectionError } from './error';
|
|
|
|
/**
|
|
* Represents an error returned by the Headscale API.
|
|
*/
|
|
export interface HeadscaleAPIError {
|
|
requestUrl: `${string} ${string}`;
|
|
statusCode: number;
|
|
rawData: string;
|
|
data: Record<string, unknown> | null;
|
|
}
|
|
|
|
/**
|
|
* Type guard to check if an error is a HeadscaleAPIError.
|
|
* @param error - The error to check.
|
|
* @returns True if the error is a HeadscaleAPIError, false otherwise.
|
|
*/
|
|
export function isApiError(error: unknown): error is HeadscaleAPIError {
|
|
return (
|
|
error != null &&
|
|
typeof error === 'object' &&
|
|
'requestUrl' in error &&
|
|
'statusCode' in error &&
|
|
'rawData' in error &&
|
|
'data' in error
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Type guard to check if an error is a HeadscaleConnectionError.
|
|
* @param error - The error to check.
|
|
* @returns True if the error is a HeadscaleConnectionError, false otherwise.
|
|
*/
|
|
export function isConnectionError(
|
|
error: unknown,
|
|
): error is HeadscaleConnectionError {
|
|
return (
|
|
error != null &&
|
|
typeof error === 'object' &&
|
|
'requestUrl' in error &&
|
|
'errorCode' in error &&
|
|
'errorMessage' in error &&
|
|
'extraData' in error
|
|
);
|
|
}
|
|
|
|
export function isDataUnauthorizedError(error: unknown): boolean {
|
|
return (
|
|
error != null &&
|
|
typeof error === 'object' &&
|
|
'data' in error &&
|
|
typeof error.data === 'object' &&
|
|
error.data != null &&
|
|
'statusCode' in error.data &&
|
|
error.data.statusCode === 401
|
|
);
|
|
}
|