diff --git a/ts/services/backups/api.ts b/ts/services/backups/api.ts index 4e7d18c6e9..a7283eba1c 100644 --- a/ts/services/backups/api.ts +++ b/ts/services/backups/api.ts @@ -224,6 +224,10 @@ export class BackupAPI { } const { subscription } = subscriptionResponse; + if (!subscription) { + return { status: 'not-found' }; + } + const { active, amount, currency, endOfCurrentPeriod, cancelAtPeriodEnd } = subscription; diff --git a/ts/textsecure/WebAPI.ts b/ts/textsecure/WebAPI.ts index 815ba744c7..4d123ece14 100644 --- a/ts/textsecure/WebAPI.ts +++ b/ts/textsecure/WebAPI.ts @@ -515,11 +515,16 @@ async function _promiseAjax( options.responseType === 'jsonwithdetails' ) { if (options.zodSchema) { - result = parseUnknown(options.zodSchema, result); + try { + result = parseUnknown(options.zodSchema, result); + } catch (e) { + log.error(logId, response.status, 'Validation error'); + throw e; + } } if (options.validateResponse) { if (!_validateResponse(result, options.validateResponse)) { - log.error(logId, response.status, 'Error'); + log.error(logId, response.status, 'Validation error'); throw makeHTTPError( 'promiseAjax: invalid response', response.status, @@ -1376,15 +1381,17 @@ const backupFileHeadersSchema = z.object({ type BackupFileHeadersType = z.infer; const subscriptionResponseSchema = z.object({ - subscription: z.object({ - level: z.number(), - billingCycleAnchor: z.coerce.date().optional(), - endOfCurrentPeriod: z.coerce.date().optional(), - active: z.boolean(), - cancelAtPeriodEnd: z.boolean().optional(), - currency: z.string().optional(), - amount: z.number().nonnegative().optional(), - }), + subscription: z + .object({ + level: z.number(), + billingCycleAnchor: z.coerce.date().optional(), + endOfCurrentPeriod: z.coerce.date().optional(), + active: z.boolean(), + cancelAtPeriodEnd: z.boolean().optional(), + currency: z.string().optional(), + amount: z.number().nonnegative().optional(), + }) + .nullish(), }); export type SubscriptionResponseType = z.infer< @@ -4706,6 +4713,9 @@ export function initialize({ subscriberId: Uint8Array ): Promise { const data = await getSubscription(subscriberId); + if (!data.subscription) { + return false; + } return data.subscription.active; }