diff --git a/app.ts b/app.ts index f34d15a..b16f878 100644 --- a/app.ts +++ b/app.ts @@ -1,6 +1,6 @@ import { App } from 'homey' // eslint-disable-line import/no-extraneous-dependencies import axios from 'axios' -import withAPI, { getAPIErrorMessage } from './mixins/withAPI' +import withAPI, { getErrorMessage } from './mixins/withAPI' import type { LoginCredentials, LoginData, @@ -11,16 +11,6 @@ import type { axios.defaults.baseURL = 'https://www.ariston-net.remotethermo.com/api/v2' -function getErrorMessage(error: unknown): string { - let errorMessage = String(error) - if (axios.isAxiosError(error)) { - errorMessage = getAPIErrorMessage(error) - } else if (error instanceof Error) { - errorMessage = error.message - } - return errorMessage -} - export = class AristonApp extends withAPI(App) { #loginTimeout!: NodeJS.Timeout diff --git a/mixins/withAPI.ts b/mixins/withAPI.ts index b1f8919..8b49847 100644 --- a/mixins/withAPI.ts +++ b/mixins/withAPI.ts @@ -18,6 +18,16 @@ export function getAPIErrorMessage(error: AxiosError): string { return error.message } +export function getErrorMessage(error: unknown): string { + let errorMessage = String(error) + if (axios.isAxiosError(error)) { + errorMessage = getAPIErrorMessage(error) + } else if (error instanceof Error) { + errorMessage = error.message + } + return errorMessage +} + export default function withAPI(base: T): APIClass & T { return class extends base { public api: AxiosInstance