Skip to content

Conversation

@webdevcody
Copy link
Collaborator

@webdevcody webdevcody commented Jan 1, 2026

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced HTTP error handling to provide more descriptive error messages when requests fail. Errors are now consistently formatted with status information and parsed error details for improved debugging.

✏️ Tip: You can customize this high-level summary in your review settings.

- Added error handling for HTTP responses in the HttpApiClient class.
- Enhanced error messages to include status text and parsed error data, improving debugging and user feedback.
@coderabbitai
Copy link

coderabbitai bot commented Jan 1, 2026

📝 Walkthrough

Walkthrough

The HttpApiClient now implements consistent error handling across all HTTP request methods (POST, GET, PUT, DELETE). When a response fails, the code constructs informative error messages from status codes and response bodies, then throws standardized errors instead of returning raw responses.

Changes

Cohort / File(s) Summary
HTTP Error Handling
apps/ui/src/lib/http-api-client.ts
Added robust error handling to all HTTP request methods. Non-2xx responses now construct descriptive error messages from status codes and attempt JSON body parsing to extract error details, with fallback to status text. Consistent Error objects are thrown instead of raw responses being returned.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 With whiskers twitched and nose held high,
HTTP errors shan't pass by—
Each status code now tells its tale,
No more shall error messages fail!
Our client stands with grace anew, 🌟

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat: improve error handling in HttpApiClient' directly and clearly summarizes the main change—adding robust HTTP error handling to the HttpApiClient methods with descriptive error messages.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @webdevcody, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the robustness of the application's HTTP communication by introducing standardized and informative error handling. It ensures that any unsuccessful API calls are caught and reported with detailed messages, which will greatly improve debugging capabilities and provide clearer feedback when issues arise.

Highlights

  • Improved Error Handling: Implemented comprehensive error handling for HTTP responses within the HttpApiClient class to ensure that failed requests are properly identified and reported.
  • Enhanced Error Messages: Error messages now include the HTTP status code and status text. Additionally, the client attempts to parse the response body for a more specific error message (e.g., errorData.error), falling back to the default status text if parsing fails.
  • Centralized Logic: The new error handling logic has been consistently applied across multiple HTTP request methods (e.g., post, get, put, delete) in http-api-client.ts.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces error handling for HTTP responses in HttpApiClient, which is a great improvement for robustness. However, the implementation introduces significant code duplication across the post, get, put, and httpDelete methods. My review focuses on refactoring this duplicated logic into a single helper method to improve maintainability. I've also identified a potential bug in the error handling logic that could cause a crash if an error response from the server is not in the expected format, and provided a fix for it.

Comment on lines +573 to 586
if (!response.ok) {
let errorMessage = `HTTP ${response.status}: ${response.statusText}`;
try {
const errorData = await response.json();
if (errorData.error) {
errorMessage = errorData.error;
}
} catch {
// If parsing JSON fails, use status text
}
throw new Error(errorMessage);
}

return response.json();
Copy link
Contributor

Choose a reason for hiding this comment

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

high

This error handling logic is duplicated across post, get, put, and httpDelete methods. Additionally, there's a potential bug: if the error response body is valid JSON but not an object (e.g., null or a string), accessing errorData.error will throw a TypeError, masking the original HTTP error.

To fix this and improve maintainability, I recommend extracting the logic into a private helper method. You can add this method to the HttpApiClient class:

private async handleHttpResponse<T>(response: Response): Promise<T> {
  if (!response.ok) {
    let errorMessage = `HTTP ${response.status}: ${response.statusText}`;
    try {
      const errorData = await response.json();
      // Use optional chaining to safely access the `error` property.
      if (errorData?.error) {
        errorMessage = errorData.error;
      }
    } catch {
      // If parsing JSON fails, fall back to the status text.
    }
    throw new Error(errorMessage);
  }
  return response.json();
}

Then, you can simplify this post method by using the new helper.

    return this.handleHttpResponse(response);

Comment on lines +597 to 610
if (!response.ok) {
let errorMessage = `HTTP ${response.status}: ${response.statusText}`;
try {
const errorData = await response.json();
if (errorData.error) {
errorMessage = errorData.error;
}
} catch {
// If parsing JSON fails, use status text
}
throw new Error(errorMessage);
}

return response.json();
Copy link
Contributor

Choose a reason for hiding this comment

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

high

Please apply the same refactoring here as suggested for the post method. Using the handleHttpResponse helper will fix the potential bug and remove duplicated code.

    return this.handleHttpResponse(response);

Comment on lines +623 to 636
if (!response.ok) {
let errorMessage = `HTTP ${response.status}: ${response.statusText}`;
try {
const errorData = await response.json();
if (errorData.error) {
errorMessage = errorData.error;
}
} catch {
// If parsing JSON fails, use status text
}
throw new Error(errorMessage);
}

return response.json();
Copy link
Contributor

Choose a reason for hiding this comment

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

high

This method also contains the duplicated error handling logic. Please refactor it to use the handleHttpResponse helper for consistency and to fix the underlying bug.

    return this.handleHttpResponse(response);

Comment on lines +648 to 661
if (!response.ok) {
let errorMessage = `HTTP ${response.status}: ${response.statusText}`;
try {
const errorData = await response.json();
if (errorData.error) {
errorMessage = errorData.error;
}
} catch {
// If parsing JSON fails, use status text
}
throw new Error(errorMessage);
}

return response.json();
Copy link
Contributor

Choose a reason for hiding this comment

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

high

To complete the refactoring, please replace the duplicated error handling logic in this method with a call to the handleHttpResponse helper as well.

    return this.handleHttpResponse(response);

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
apps/ui/src/lib/http-api-client.ts (1)

573-584: Extract duplicate error handling into a shared helper method.

The error handling logic is duplicated across all four HTTP methods (post, get, put, httpDelete). Extracting this into a private helper method would improve maintainability and ensure consistent error handling.

🔎 Suggested refactor

Add a private helper method:

+  private async handleErrorResponse(response: Response): Promise<never> {
+    let errorMessage = `HTTP ${response.status}: ${response.statusText}`;
+    try {
+      const errorData = await response.json();
+      if (errorData.error) {
+        errorMessage = errorData.error;
+      }
+    } catch {
+      // If parsing JSON fails, use status text
+    }
+    throw new Error(errorMessage);
+  }

Then simplify each method:

   private async post<T>(endpoint: string, body?: unknown): Promise<T> {
     await waitForApiKeyInit();
     const response = await fetch(`${this.serverUrl}${endpoint}`, {
       method: 'POST',
       headers: this.getHeaders(),
       credentials: 'include',
       body: body ? JSON.stringify(body) : undefined,
     });

     if (!response.ok) {
-      let errorMessage = `HTTP ${response.status}: ${response.statusText}`;
-      try {
-        const errorData = await response.json();
-        if (errorData.error) {
-          errorMessage = errorData.error;
-        }
-      } catch {
-        // If parsing JSON fails, use status text
-      }
-      throw new Error(errorMessage);
+      await this.handleErrorResponse(response);
     }

     return response.json();
   }

Apply the same pattern to get, put, and httpDelete.

Also applies to: 597-608, 623-634, 648-659

📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8c8a487 and 50aac1c.

📒 Files selected for processing (1)
  • apps/ui/src/lib/http-api-client.ts
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (CLAUDE.md)

Always import from shared packages (@automaker/*), never from old relative paths

Files:

  • apps/ui/src/lib/http-api-client.ts
**/*.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

Use resolveModelString() from @automaker/model-resolver to convert model aliases (haiku, sonnet, opus) to full model names

Files:

  • apps/ui/src/lib/http-api-client.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: e2e
🔇 Additional comments (1)
apps/ui/src/lib/http-api-client.ts (1)

573-584: Good addition of comprehensive error handling.

The error handling implementation correctly extracts detailed error information from HTTP responses and provides informative error messages for debugging. The pattern of attempting to parse JSON error data while gracefully falling back to status text is sound.

Also applies to: 597-608, 623-634, 648-659

@webdevcody webdevcody merged commit 90e62b8 into main Jan 1, 2026
12 checks passed
@webdevcody webdevcody deleted the addressing-pr-issues branch January 1, 2026 07:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants