Skip to content

Commit

Permalink
improve
Browse files Browse the repository at this point in the history
  • Loading branch information
OlivierZal committed Mar 31, 2024
1 parent 82e017f commit 28a7e51
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions ariston/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,6 @@ interface SettingManager {
const DOMAIN = 'https://www.ariston-net.remotethermo.com'
const LOGIN_URL = '/R2/Account/Login'

const throwIfRequested = (error: unknown, raise: boolean): void => {
if (raise) {
throw new Error(error instanceof Error ? error.message : String(error))
}
}

export default class AristonAPI {
#retry = true

Expand Down Expand Up @@ -75,20 +69,22 @@ export default class AristonAPI {
this.#setupAxiosInterceptors()
}

public async applyLogin(
{ password, username }: LoginCredentials = {
public async applyLogin(data?: LoginCredentials): Promise<boolean> {
const { password, username } = data ?? {
password: this.#settingManager.get('password') ?? '',
username: this.#settingManager.get('username') ?? '',
},
raise = false,
): Promise<boolean> {
}
if (username && password) {
try {
return (
await this.login({ email: username, password, rememberMe: true })
).data.ok
} catch (error) {
throwIfRequested(error, raise)
if (typeof data !== 'undefined') {
throw new Error(
error instanceof Error ? error.message : String(error),
)
}
}
}
return false
Expand Down

0 comments on commit 28a7e51

Please sign in to comment.