Skip to content

Commit

Permalink
improve error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
OlivierZal committed Nov 13, 2023
1 parent 8efb1b4 commit 4a36abc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions app.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { App } from 'homey' // eslint-disable-line import/no-extraneous-dependencies
import axios from 'axios'
import withAPI from './mixins/withAPI'
import withAPI, { getErrorMessage } from './mixins/withAPI'
import type {
LoginCredentials,
LoginData,
Expand Down Expand Up @@ -50,7 +50,13 @@ export = class AristonApp extends withAPI(App) {
this.refreshLogin(loginCredentials)
return true
} catch (error: unknown) {
throw new Error(error instanceof Error ? error.message : String(error))
let errorMessage = String(error)
if (axios.isAxiosError(error)) {
errorMessage = getErrorMessage(error)
} else if (error instanceof Error) {
errorMessage = error.message
}
throw new Error(errorMessage)
}
}

Expand Down
2 changes: 1 addition & 1 deletion mixins/withAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type APIClass = new (...args: any[]) => {
api: AxiosInstance
}

function getErrorMessage(error: AxiosError): string {
export function getErrorMessage(error: AxiosError): string {
return error.message
}

Expand Down

0 comments on commit 4a36abc

Please sign in to comment.