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() {