From 6f8f79df278808ebae6b83ba49c1243a4d7647b3 Mon Sep 17 00:00:00 2001 From: guillermo dieguez Date: Fri, 27 Dec 2024 09:54:32 -0300 Subject: [PATCH] =?UTF-8?q?=E2=8F=AA=20app:=20roll=20back=20api=20response?= =?UTF-8?q?=20handling?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .changeset/soft-ads-share.md | 5 ++++ src/utils/server.ts | 45 ++++++++++++++---------------------- 2 files changed, 22 insertions(+), 28 deletions(-) create mode 100644 .changeset/soft-ads-share.md diff --git a/.changeset/soft-ads-share.md b/.changeset/soft-ads-share.md new file mode 100644 index 00000000..d025c015 --- /dev/null +++ b/.changeset/soft-ads-share.md @@ -0,0 +1,5 @@ +--- +"@exactly/mobile": patch +--- + +⏪ roll back api response handling diff --git a/src/utils/server.ts b/src/utils/server.ts index bf0bd052..c433f93a 100644 --- a/src/utils/server.ts +++ b/src/utils/server.ts @@ -55,10 +55,7 @@ export async function registrationOptions() { export async function verifyRegistration(attestation: RegistrationResponseJSON) { const response = await client.api.auth.registration.$post({ json: attestation }); - if (!response.ok) { - const raw = response.clone(); - throw new APIError(response.status, await response.json().catch(() => raw.text())); - } + if (!response.ok) throw new APIError(response.status, await response.json()); const { auth: expires, ...passkey } = await response.json(); await queryClient.setQueryData(["auth"], parse(Auth, expires)); return parse(Passkey, passkey); @@ -67,57 +64,50 @@ export async function verifyRegistration(attestation: RegistrationResponseJSON) export async function getCard() { await auth(); const response = await client.api.card.$get(); - const text = await response.text(); - if (!response.ok) throw new APIError(response.status, text); - return JSON.parse(text) as Awaited>; + if (!response.ok) throw new APIError(response.status, await response.json()); + return response.json(); } export async function createCard() { await auth(); const response = await client.api.card.$post(); - const text = await response.text(); - if (!response.ok) throw new APIError(response.status, text); - return JSON.parse(text) as Awaited>; + if (!response.ok) throw new APIError(response.status, await response.json()); + return response.json(); } export async function setCardStatus(status: "ACTIVE" | "FROZEN") { await auth(); const response = await client.api.card.$patch({ json: { status } }); - const text = await response.text(); - if (!response.ok) throw new APIError(response.status, text); - return JSON.parse(text) as Awaited>; + if (!response.ok) throw new APIError(response.status, await response.json()); + return response.json(); } export async function setCardMode(mode: number) { await auth(); const response = await client.api.card.$patch({ json: { mode } }); - const text = await response.text(); - if (!response.ok) throw new APIError(response.status, text); - return JSON.parse(text) as Awaited>; + if (!response.ok) throw new APIError(response.status, await response.json()); + return response.json(); } export async function getKYCLink() { await auth(); const response = await client.api.kyc.$post(); - const text = await response.text(); - if (!response.ok) throw new APIError(response.status, text); - return JSON.parse(text) as Awaited>; + if (!response.ok) throw new APIError(response.status, await response.json()); + return response.json(); } export async function getKYCStatus() { await auth(); const response = await client.api.kyc.$get(); - const text = await response.text(); - if (!response.ok) throw new APIError(response.status, text); - return JSON.parse(text) as Awaited>; + if (!response.ok) throw new APIError(response.status, await response.json()); + return response.json(); } export async function getPasskey() { await auth(); const response = await client.api.passkey.$get(); - const text = await response.text(); - if (!response.ok) throw new APIError(response.status, text); - return JSON.parse(text) as Awaited>; + if (!response.ok) throw new APIError(response.status, await response.json()); + return response.json(); } export async function getActivity(parameters?: NonNullable[0]>["query"]) { @@ -125,9 +115,8 @@ export async function getActivity(parameters?: NonNullable>; + if (!response.ok) throw new APIError(response.status, await response.json()); + return response.json(); } export async function auth() {