Skip to content

A modern and easy to use dashboard. 80+ integrations. 20K+ icons built in. Authentication out of the box. No YAML, drag and drop configuration.

1.3 KB
Raw Blame
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;
  }
}