Files
dpu-shared/src/fastify.ts
2026-02-08 12:52:19 +01:00

51 lines
911 B
TypeScript

import type { AxiosInstance } from "axios";
import { logWarning } from "./logger.js";
export type ServiceResult<T = unknown> = {
result: T;
successful: boolean;
};
export class API_Error {
constructor(public error: string) {}
}
export abstract class BaseClient {
private axiosInstance: AxiosInstance;
constructor(axiosInstance: AxiosInstance) {
this.axiosInstance = axiosInstance;
}
getAxios(): AxiosInstance {
return this.axiosInstance;
}
}
export abstract class BaseService<T> {
private client: T;
constructor(client: T) {
this.client = client;
}
getClient(): T {
return this.client;
}
getSuccessfulResult<R = unknown>(result: R): ServiceResult<R> {
return {
result,
successful: true,
};
}
getErrorResult(errorMessage: string, error?: unknown): ServiceResult<string> {
logWarning(errorMessage);
return {
result: errorMessage,
successful: false,
};
}
}