fix: some integrations handle parse errors wrong (#3746)
This commit is contained in:
@@ -3,8 +3,10 @@ import { logger } from "@homarr/log";
|
|||||||
|
|
||||||
import type { Integration } from "../integration";
|
import type { Integration } from "../integration";
|
||||||
import type { IIntegrationErrorHandler } from "./handler";
|
import type { IIntegrationErrorHandler } from "./handler";
|
||||||
|
import { integrationFetchHttpErrorHandler } from "./http";
|
||||||
import { IntegrationError } from "./integration-error";
|
import { IntegrationError } from "./integration-error";
|
||||||
import { IntegrationUnknownError } from "./integration-unknown-error";
|
import { IntegrationUnknownError } from "./integration-unknown-error";
|
||||||
|
import { integrationJsonParseErrorHandler, integrationZodParseErrorHandler } from "./parse";
|
||||||
|
|
||||||
const localLogger = logger.child({
|
const localLogger = logger.child({
|
||||||
module: "HandleIntegrationErrors",
|
module: "HandleIntegrationErrors",
|
||||||
@@ -13,7 +15,14 @@ const localLogger = logger.child({
|
|||||||
// eslint-disable-next-line @typescript-eslint/no-empty-object-type, @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-empty-object-type, @typescript-eslint/no-explicit-any
|
||||||
type AbstractConstructor<T = {}> = abstract new (...args: any[]) => T;
|
type AbstractConstructor<T = {}> = abstract new (...args: any[]) => T;
|
||||||
|
|
||||||
|
const defaultErrorHandlers: IIntegrationErrorHandler[] = [
|
||||||
|
integrationZodParseErrorHandler,
|
||||||
|
integrationJsonParseErrorHandler,
|
||||||
|
integrationFetchHttpErrorHandler,
|
||||||
|
];
|
||||||
|
|
||||||
export const HandleIntegrationErrors = (errorHandlers: IIntegrationErrorHandler[]) => {
|
export const HandleIntegrationErrors = (errorHandlers: IIntegrationErrorHandler[]) => {
|
||||||
|
const combinedErrorHandlers = [...defaultErrorHandlers, ...errorHandlers];
|
||||||
return <T extends AbstractConstructor<Integration>>(IntegrationBaseClass: T): T => {
|
return <T extends AbstractConstructor<Integration>>(IntegrationBaseClass: T): T => {
|
||||||
abstract class ErrorHandledIntegration extends IntegrationBaseClass {
|
abstract class ErrorHandledIntegration extends IntegrationBaseClass {
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
@@ -42,7 +51,7 @@ export const HandleIntegrationErrors = (errorHandlers: IIntegrationErrorHandler[
|
|||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const handler of errorHandlers) {
|
for (const handler of combinedErrorHandlers) {
|
||||||
const handledError = handler.handleError(error, this.publicIntegration);
|
const handledError = handler.handleError(error, this.publicIntegration);
|
||||||
if (!handledError) continue;
|
if (!handledError) continue;
|
||||||
|
|
||||||
|
|||||||
@@ -8,8 +8,6 @@ import { removeTrailingSlash } from "@homarr/common";
|
|||||||
import type { IntegrationSecretKind } from "@homarr/definitions";
|
import type { IntegrationSecretKind } from "@homarr/definitions";
|
||||||
|
|
||||||
import { HandleIntegrationErrors } from "./errors/decorator";
|
import { HandleIntegrationErrors } from "./errors/decorator";
|
||||||
import { integrationFetchHttpErrorHandler } from "./errors/http";
|
|
||||||
import { integrationJsonParseErrorHandler, integrationZodParseErrorHandler } from "./errors/parse";
|
|
||||||
import { TestConnectionError } from "./test-connection/test-connection-error";
|
import { TestConnectionError } from "./test-connection/test-connection-error";
|
||||||
import type { TestingResult } from "./test-connection/test-connection-service";
|
import type { TestingResult } from "./test-connection/test-connection-service";
|
||||||
import { TestConnectionService } from "./test-connection/test-connection-service";
|
import { TestConnectionService } from "./test-connection/test-connection-service";
|
||||||
@@ -32,11 +30,7 @@ export interface IntegrationTestingInput {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@HandleIntegrationErrors([
|
@HandleIntegrationErrors([])
|
||||||
integrationZodParseErrorHandler,
|
|
||||||
integrationJsonParseErrorHandler,
|
|
||||||
integrationFetchHttpErrorHandler,
|
|
||||||
])
|
|
||||||
export abstract class Integration {
|
export abstract class Integration {
|
||||||
constructor(protected integration: IntegrationInput) {}
|
constructor(protected integration: IntegrationInput) {}
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ import { fetchWithTrustedCertificatesAsync } from "@homarr/certificates/server";
|
|||||||
import { ParseError, ResponseError } from "@homarr/common/server";
|
import { ParseError, ResponseError } from "@homarr/common/server";
|
||||||
|
|
||||||
import { createChannelEventHistoryOld } from "../../../redis/src/lib/channel";
|
import { createChannelEventHistoryOld } from "../../../redis/src/lib/channel";
|
||||||
import { HandleIntegrationErrors } from "../base/errors/decorator";
|
|
||||||
import type { IntegrationTestingInput } from "../base/integration";
|
import type { IntegrationTestingInput } from "../base/integration";
|
||||||
import { Integration } from "../base/integration";
|
import { Integration } from "../base/integration";
|
||||||
import { TestConnectionError } from "../base/test-connection/test-connection-error";
|
import { TestConnectionError } from "../base/test-connection/test-connection-error";
|
||||||
@@ -22,7 +21,6 @@ import {
|
|||||||
opnsenseSystemSummarySchema,
|
opnsenseSystemSummarySchema,
|
||||||
} from "./opnsense-types";
|
} from "./opnsense-types";
|
||||||
|
|
||||||
@HandleIntegrationErrors([])
|
|
||||||
export class OPNsenseIntegration extends Integration implements FirewallSummaryIntegration {
|
export class OPNsenseIntegration extends Integration implements FirewallSummaryIntegration {
|
||||||
protected async testingAsync(input: IntegrationTestingInput): Promise<TestingResult> {
|
protected async testingAsync(input: IntegrationTestingInput): Promise<TestingResult> {
|
||||||
const response = await input.fetchAsync(this.url("/api/diagnostics/system/system_information"), {
|
const response = await input.fetchAsync(this.url("/api/diagnostics/system/system_information"), {
|
||||||
|
|||||||
Reference in New Issue
Block a user