feat(integration): improve integration test connection (#3005)
This commit is contained in:
1 parent
3daf1c8341
commit
ef9a5e9895
111 files changed
+7168
-976
No files matched your search
@@ -0,0 +1,13 @@
|
||||
import {
|
||||
AxiosHttpErrorHandler,
|
||||
FetchHttpErrorHandler,
|
||||
OFetchHttpErrorHandler,
|
||||
TsdavHttpErrorHandler,
|
||||
} from "@homarr/common/server";
|
||||
|
||||
import { IntegrationHttpErrorHandler } from "./integration-http-error-handler";
|
||||
|
||||
export const integrationFetchHttpErrorHandler = new IntegrationHttpErrorHandler(new FetchHttpErrorHandler());
|
||||
export const integrationOFetchHttpErrorHandler = new IntegrationHttpErrorHandler(new OFetchHttpErrorHandler());
|
||||
export const integrationAxiosHttpErrorHandler = new IntegrationHttpErrorHandler(new AxiosHttpErrorHandler());
|
||||
export const integrationTsdavHttpErrorHandler = new IntegrationHttpErrorHandler(new TsdavHttpErrorHandler());
|
||||
@@ -0,0 +1,26 @@
|
||||
import { RequestError, ResponseError } from "@homarr/common/server";
|
||||
import type { HttpErrorHandler } from "@homarr/common/server";
|
||||
|
||||
import type { IIntegrationErrorHandler } from "../handler";
|
||||
import type { IntegrationError, IntegrationErrorData } from "../integration-error";
|
||||
import { IntegrationRequestError } from "./integration-request-error";
|
||||
import { IntegrationResponseError } from "./integration-response-error";
|
||||
|
||||
export class IntegrationHttpErrorHandler implements IIntegrationErrorHandler {
|
||||
private readonly httpErrorHandler: HttpErrorHandler;
|
||||
|
||||
constructor(httpErrorHandler: HttpErrorHandler) {
|
||||
this.httpErrorHandler = httpErrorHandler;
|
||||
}
|
||||
|
||||
handleError(error: unknown, integration: IntegrationErrorData): IntegrationError | undefined {
|
||||
if (error instanceof RequestError) return new IntegrationRequestError(integration, { cause: error });
|
||||
if (error instanceof ResponseError) return new IntegrationResponseError(integration, { cause: error });
|
||||
|
||||
const requestError = this.httpErrorHandler.handleRequestError(error);
|
||||
if (requestError) return new IntegrationRequestError(integration, { cause: requestError });
|
||||
const responseError = this.httpErrorHandler.handleResponseError(error);
|
||||
if (responseError) return new IntegrationResponseError(integration, { cause: responseError });
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import type { AnyRequestError, RequestError, RequestErrorType } from "@homarr/common/server";
|
||||
|
||||
import type { IntegrationErrorData } from "../integration-error";
|
||||
import { IntegrationError } from "../integration-error";
|
||||
|
||||
export type IntegrationRequestErrorOfType<TType extends RequestErrorType> = IntegrationRequestError & {
|
||||
cause: RequestError<TType>;
|
||||
};
|
||||
|
||||
export class IntegrationRequestError extends IntegrationError {
|
||||
constructor(integration: IntegrationErrorData, { cause }: { cause: AnyRequestError }) {
|
||||
super(integration, "Request to integration failed", { cause });
|
||||
this.name = IntegrationRequestError.name;
|
||||
}
|
||||
|
||||
get cause(): AnyRequestError {
|
||||
return super.cause as AnyRequestError;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import type { ResponseError } from "@homarr/common/server";
|
||||
|
||||
import type { IntegrationErrorData } from "../integration-error";
|
||||
import { IntegrationError } from "../integration-error";
|
||||
|
||||
export class IntegrationResponseError extends IntegrationError {
|
||||
constructor(integration: IntegrationErrorData, { cause }: { cause: ResponseError }) {
|
||||
super(integration, "Response from integration did not indicate success", { cause });
|
||||
this.name = IntegrationResponseError.name;
|
||||
}
|
||||
|
||||
get cause(): ResponseError {
|
||||
return super.cause as ResponseError;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user