From 19bb77db88584099094728eab9c3e9baee1a91ae Mon Sep 17 00:00:00 2001 From: Ong Jun Xiong Date: Thu, 2 Nov 2023 18:33:07 +0800 Subject: [PATCH] handle more error cases for userHandler --- bash.exe.stackdump | 44 +++++++++++++++++++++++++++ frontend/src/pages/api/userHandler.ts | 27 +++++++++++----- 2 files changed, 64 insertions(+), 7 deletions(-) create mode 100644 bash.exe.stackdump diff --git a/bash.exe.stackdump b/bash.exe.stackdump new file mode 100644 index 00000000..deaedace --- /dev/null +++ b/bash.exe.stackdump @@ -0,0 +1,44 @@ +Exception: STATUS_STACK_OVERFLOW at rip=0010040B625 +rax=0000000000000000 rbx=00000000FFE04040 rcx=0000000000000000 +rdx=0000000000000000 rsi=00000001004F73A0 rdi=00000000000000C8 +r8 =0000000000000000 r9 =00000000FFFFDE08 r10=00000000FFFFE458 +r11=0000000100000000 r12=0000000000000000 r13=0000000800641E70 +r14=0000000000000000 r15=00000000FFFFFFFF +rbp=0000000000000000 rsp=00000000FFE03E40 +program=C:\Program Files\Git\usr\bin\bash.exe, pid 1795, thread +cs=0033 ds=002B es=002B fs=0053 gs=002B ss=002B +Stack trace: +Frame Function Args +00000000000 0010040B625 (001004036F5, 00000000010, 00000000000, 000FFE04DB0) +00000000010 00100401FFA (00210199B0B, 00800082CE0, 00800642000, 00800641E70) +00000000010 0010046ED5C (001004FA2EA, 00000000415, 0021032C948, 00000000000) +00000000010 0010044A6AF (0010000001F, 00000000000, 00000000010, 001004FA2EA) +00800641CB0 00100417AD9 (00210199B0B, 00800082CE0, 008006415A0, 00800641CB0) +00000000010 0010046F115 (001004FA2EA, 00000000415, 0021032C948, 00000000000) +00000000010 0010044A6AF (0010000001F, 00000000000, 00000000010, 001004FA2EA) +00800641250 00100417AD9 (00210199B0B, 00800082CE0, 00800640B40, 00800641250) +00000000010 0010046F115 (001004FA2EA, 00000000415, 0021032C948, 00000000000) +00000000010 0010044A6AF (0010000001F, 00000000000, 00000000010, 001004FA2EA) +008006407F0 00100417AD9 (00210199B0B, 00800082CE0, 008006400E0, 008006407F0) +00000000010 0010046F115 (001004FA2EA, 00000000415, 0021032C948, 00000000000) +00000000010 0010044A6AF (0010000001F, 00000000000, 00000000010, 001004FA2EA) +0080063FD90 00100417AD9 (00210199B0B, 00800082CE0, 0080063F680, 0080063FD90) +00000000010 0010046F115 (001004FA2EA, 00000000415, 0021032C948, 00000000000) +00000000010 0010044A6AF (0010000001F, 00000000000, 00000000010, 001004FA2EA) +0080063F330 00100417AD9 (00210199B0B, 00800082CE0, 0080063EC20, 0080063F330) +00000000010 0010046F115 (001004FA2EA, 00000000415, 0021032C948, 00000000000) +00000000010 0010044A6AF (0010000001F, 00000000000, 00000000010, 001004FA2EA) +0080063E8D0 00100417AD9 (00210199B0B, 00800082CE0, 0080063E1C0, 0080063E8D0) +00000000010 0010046F115 (001004FA2EA, 00000000415, 0021032C948, 00000000000) +00000000010 0010044A6AF (0010000001F, 00000000000, 00000000010, 001004FA2EA) +0080063DE70 00100417AD9 (00210199B0B, 00800082CE0, 0080063D760, 0080063DE70) +00000000010 0010046F115 (001004FA2EA, 00000000415, 0021032C948, 00000000000) +00000000010 0010044A6AF (0010000001F, 00000000000, 00000000010, 001004FA2EA) +0080063D410 00100417AD9 (00210199B0B, 00800082CE0, 0080063CD00, 0080063D410) +00000000010 0010046F115 (001004FA2EA, 00000000415, 0021032C948, 00000000000) +00000000010 0010044A6AF (0010000001F, 00000000000, 00000000010, 001004FA2EA) +0080063C9B0 00100417AD9 (00210199B0B, 00800082CE0, 0080063C2A0, 0080063C9B0) +00000000010 0010046F115 (001004FA2EA, 00000000415, 0021032C948, 00000000000) +00000000010 0010044A6AF (0010000001F, 00000000000, 00000000010, 001004FA2EA) +0080063BF50 00100417AD9 (00210199B0B, 00800082CE0, 0080063B840, 0080063BF50) +End of stack trace (more stack frames may be present) diff --git a/frontend/src/pages/api/userHandler.ts b/frontend/src/pages/api/userHandler.ts index 02586dce..05acf086 100644 --- a/frontend/src/pages/api/userHandler.ts +++ b/frontend/src/pages/api/userHandler.ts @@ -14,14 +14,19 @@ export const updateUserByUid = async (user: EditableUser, currentUser: any) => { headers: { "Content-Type": "application/json", "User-Id-Token": idToken, - "User-Id": currentUser.uid + "User-Id": currentUser.uid, }, body: JSON.stringify(user), }); - const data = await response.json(); if (response.status === 201) { + const data = await response.json(); return data; + } else { + const text = await response.text(); + throw new Error( + `Unexpected response (status: ${response.status}): ${text}` + ); } } catch (error) { console.error("There was an error updating the user", error); @@ -40,18 +45,26 @@ export const getUserByUid = async (uid: string, currentUser: any) => { headers: { "Content-Type": "application/json", "User-Id-Token": idToken, - "User-Id": currentUser.uid + "User-Id": currentUser.uid, }, }); - const data = await response.json(); - if (response.status === 200) { + if ( + response.ok && + response.headers.get("Content-Type")?.includes("application/json") + ) { + const data = await response.json(); return data; + } else if (response.status === 204) { + return null; } else { - throw new Error(response.statusText); + const text = await response.text(); + throw new Error( + `Unexpected response (status: ${response.status}): ${text}` + ); } } catch (error) { console.error("There was an error getting the user", error); throw error; } -}; \ No newline at end of file +};