diff --git a/src/services/EmailVerifySvr.ts b/src/services/EmailVerifySvr.ts index e6c28d9..06c2a23 100644 --- a/src/services/EmailVerifySvr.ts +++ b/src/services/EmailVerifySvr.ts @@ -8,16 +8,28 @@ export class EmailVerifySvr { * Checks if the user's email is verified * @returns an object containing the verification status and the user's email */ - public async checkEmailVerified() { + public async checkEmailVerified(): Promise<{ + verified: number; + email: string | null; + }> { let res = await isEmailVerified(); - let verified = 0; - let email = ""; - if (!res.errcode) { - verified = res.data.verified; - email = res.data?.email; + if (res.errcode) { + throw new Error("Failed to fetch email verification status"); //Throw error if call to the checking function fails } + + const { data } = res; + if (!data) { + throw new Error("Invalid response from the server"); //Throw error if the expected data structure is missing + } + + const { verified, email } = data; + if (!email || typeof verified !== "number") { + throw new Error("Invalid values returned from server"); //Throw error if the data doesn't have the expected types or values + } + return { verified, email }; } + /** * Begins the process of verifying the user's email * @param email - the email to be verified diff --git a/src/services/PaySvr.ts b/src/services/PaySvr.ts index 9ccb2ca..c41283b 100644 --- a/src/services/PaySvr.ts +++ b/src/services/PaySvr.ts @@ -10,6 +10,19 @@ export class PaySvr { * @returns The result of the alchemyPrePay function. */ public async alchemyPrePay(data: IPayData) { - return alchemyPrePay(data); + let res = await alchemyPrePay(data); + if (res.errcode) { + throw new Error(res.errmsg); + } + if (!res.data) { + throw new Error("No data returned"); + } + const url = res.data.url; + if (!url) { + throw new Error("No url returned"); + } + jsb.showWebPage(url); + // jsb.openURL(url); + return true; } }