From b7a948478546824e2989bd72d0af4e7211150a61 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Wed, 20 Mar 2024 12:58:31 -0400 Subject: [PATCH] refactor: update some of the methods to return an error in the try catch/vs a false --- src/account.ts | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/src/account.ts b/src/account.ts index a28e756..912ea24 100644 --- a/src/account.ts +++ b/src/account.ts @@ -72,14 +72,16 @@ export class AccountApi { return false; } - public async register(registerRequest: RegisterRequest): Promise { + public async register( + registerRequest: RegisterRequest, + ): Promise { let ret: AxiosResponse; try { ret = await postApiAuthRegister(registerRequest, { baseURL: this.apiUrl, }); } catch (e) { - return false; + return new Error((e as AxiosError).response?.data as string); } return this.checkSuccessBool(ret); @@ -87,7 +89,7 @@ export class AccountApi { public async verifyEmail( verifyEmailRequest: VerifyEmailRequest, - ): Promise { + ): Promise { let ret: AxiosResponse; try { ret = await postApiAccountVerifyEmail( @@ -95,22 +97,24 @@ export class AccountApi { this.buildOptions(), ); } catch (e) { - return false; + return new Error((e as AxiosError).response?.data as string); } return this.checkSuccessBool(ret); } - public async generateOtp(): Promise { + public async generateOtp(): Promise { let ret: AxiosResponse; try { ret = await getApiAuthOtpGenerate(this.buildOptions()); } catch (e) { - return false; + return new Error((e as AxiosError).response?.data as string); } return this.checkSuccessVal(ret); } - public async verifyOtp(otpVerifyRequest: OTPVerifyRequest): Promise { + public async verifyOtp( + otpVerifyRequest: OTPVerifyRequest, + ): Promise { let ret: AxiosResponse; try { ret = await postApiAccountOtpVerify( @@ -118,14 +122,14 @@ export class AccountApi { this.buildOptions(), ); } catch (e) { - return false; + return new Error((e as AxiosError).response?.data as string); } return this.checkSuccessBool(ret); } public async validateOtp( otpValidateRequest: OTPValidateRequest, - ): Promise { + ): Promise { let ret: AxiosResponse; try { ret = await postApiAccountOtpValidate( @@ -133,26 +137,26 @@ export class AccountApi { this.buildOptions(), ); } catch (e) { - return false; + return new Error((e as AxiosError).response?.data as string); } return this.checkSuccessBool(ret); } public async disableOtp( otpDisableRequest: OTPDisableRequest, - ): Promise { + ): Promise { let ret: AxiosResponse; try { ret = await postApiAuthOtpDisable(otpDisableRequest, this.buildOptions()); } catch (e) { - return false; + return new Error((e as AxiosError).response?.data as string); } return this.checkSuccessBool(ret); } public async requestPasswordReset( passwordResetRequest: PasswordResetRequest, - ): Promise { + ): Promise { let ret: AxiosResponse; try { ret = await postApiAccountPasswordResetRequest( @@ -160,14 +164,14 @@ export class AccountApi { this.buildOptions(), ); } catch (e) { - return false; + return new Error((e as AxiosError).response?.data as string); } return this.checkSuccessBool(ret); } public async confirmPasswordReset( passwordResetVerifyRequest: PasswordResetVerifyRequest, - ): Promise { + ): Promise { let ret: AxiosResponse; try { ret = await postApiAccountPasswordResetConfirm( @@ -175,7 +179,7 @@ export class AccountApi { this.buildOptions(), ); } catch (e) { - return false; + return new Error((e as AxiosError).response?.data as string); } return this.checkSuccessBool(ret); } @@ -208,11 +212,11 @@ export class AccountApi { return this.checkSuccessVal(ret); } - public async logout(): Promise { + public async logout(): Promise { try { await postApiAuthLogout(this.buildOptions()); } catch (e) { - return false; + return new Error((e as AxiosError).response?.data as string); } this._jwtToken = undefined;