mirror of
https://github.com/tale/headplane.git
synced 2026-08-24 11:36:31 +00:00
feat: switch machine apis to new runtime api client
This commit is contained in:
@@ -1,26 +1,6 @@
|
||||
import { data } from 'react-router';
|
||||
import { errors } from 'undici';
|
||||
|
||||
// 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<string, unknown>;
|
||||
|
||||
constructor(status: number, response: string, requestUrl: string) {
|
||||
super(`${requestUrl}: status ${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 {}
|
||||
}
|
||||
}
|
||||
|
||||
function isNodeNetworkError(error: unknown): error is NodeJS.ErrnoException {
|
||||
if (typeof error !== 'object' || error === null) {
|
||||
return false;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { HeadscaleApiInterface } from '../api';
|
||||
import type { HeadscaleApiInterface } from '../api';
|
||||
|
||||
/**
|
||||
* Creates a strongly-typed group factory for a given endpoint interface.
|
||||
|
||||
@@ -3,14 +3,12 @@ import { readFile } from 'node:fs/promises';
|
||||
import { dereference } from '@readme/openapi-parser';
|
||||
import type { OpenAPIV2 } from 'openapi-types';
|
||||
import { Agent, type Dispatcher, request } from 'undici';
|
||||
import type { Key, Machine, PreAuthKey, User } from '~/types';
|
||||
import log from '~/utils/log';
|
||||
import endpointSets, { RuntimeApiClient } from './endpoints';
|
||||
import ResponseError, { friendlyError } from './error';
|
||||
import { friendlyError } from './error';
|
||||
import ResponseError from './response-error';
|
||||
import { detectApiVersion, isAtLeast, type Version } from './version';
|
||||
|
||||
export type RuntimeApiClient2 = {};
|
||||
|
||||
/**
|
||||
* A low-level composed interface for interacting with the Headscale API.
|
||||
* This interface provides direct access to the underlying Undici agent
|
||||
|
||||
@@ -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<string, unknown>;
|
||||
|
||||
constructor(status: number, response: string, requestUrl: string) {
|
||||
super(`${requestUrl}: status ${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 {}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user