Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/core/hooks/use-authenticated-endpoint.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ export function useAuthenticatedEndpoint(endpoint: string, payload: { [key: stri

const body = await response.json();
if (!response.ok) {
throw new Error(body.message || `Request failed (${response.status})`);
const detail = body.error ? `${body.message}: ${body.error}` : body.message;
throw new Error(detail || `Request failed (${response.status})`);
Comment on lines +21 to +22
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Avoid "undefined: ..." in composed server error messages.

If body.error is present but body.message is absent, Line 21 can produce a malformed message (for example, "undefined: actual error"). Build the message from available parts only.

Suggested fix
-      const detail = body.error ? `${body.message}: ${body.error}` : body.message;
+      const detail = [body.message, body.error].filter(Boolean).join(': ');
       throw new Error(detail || `Request failed (${response.status})`);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const detail = body.error ? `${body.message}: ${body.error}` : body.message;
throw new Error(detail || `Request failed (${response.status})`);
const detail = [body.message, body.error].filter(Boolean).join(': ');
throw new Error(detail || `Request failed (${response.status})`);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/core/hooks/use-authenticated-endpoint.tsx` around lines 21 - 22, In
use-authenticated-endpoint (around the const detail assignment) avoid composing
`"undefined: ..."` by building the error text from only defined parts: combine
body.message and body.error with a separator only if they exist (e.g., join
non-empty values), assign that result to detail, then throw new Error(detail ||
`Request failed (${response.status})`); update the logic that sets detail
(currently referencing body.message and body.error) so it filters out
undefined/null/empty values before joining.

}
return body;
};
Expand Down
Loading