Skip to content

Un-deprecate Config.httpClient and improve it #1979

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

flevi29
Copy link
Collaborator

@flevi29 flevi29 commented Jul 2, 2025

Pull Request

Related issue

Fixes #1824

What does this PR do?

  • Breaking:
    • changes MeiliSearchApiError constructor parameters
    • changes Config.httpClient function (check documentation)
  • adds detailed documentation for above changes

Summary by CodeRabbit

  • New Features

    • Improved error handling for custom HTTP client integrations, providing clearer error messages and additional error details when requests fail.
  • Bug Fixes

    • Enhanced reliability of error reporting when using custom HTTP clients.
  • Tests

    • Added and updated tests to verify improved error handling and ensure correct behavior for both successful and failed custom HTTP client responses.

@flevi29 flevi29 added the breaking-change The related changes are breaking for the users label Jul 2, 2025
Copy link

coderabbitai bot commented Jul 2, 2025

Walkthrough

The changes refactor error handling and custom HTTP client integration. The MeiliSearchApiError class is decoupled from the Response object, now supporting generic error details and flexible construction. The custom HTTP client interface is updated to return a structured result type indicating success or failure. Tests are updated to reflect these changes and a new failure-handling test is added.

Changes

File(s) Change Summary
src/errors/meilisearch-api-error.ts Refactored MeiliSearchApiError constructor to accept a message or error response and generic details; removed response property.
src/types/types.ts Introduced CustomHttpClientResult type; updated Config.httpClient to use this type; improved documentation/comments.
src/http-requests.ts Updated request handling to use the new CustomHttpClientResult structure for custom HTTP clients and improved error logic.
tests/client.test.ts Updated tests to use new HTTP client result structure; added a test for custom client error handling and error cause assertions.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant HttpRequests
    participant CustomHttpClient
    participant MeiliSearchApiError

    Client->>HttpRequests: make request
    HttpRequests->>CustomHttpClient: call httpClient(...)
    CustomHttpClient-->>HttpRequests: return {success, value, details}
    alt success = true
        HttpRequests-->>Client: return value
    else success = false
        HttpRequests->>MeiliSearchApiError: throw with value, details
        MeiliSearchApiError-->>HttpRequests: error instance
        HttpRequests-->>Client: throw error
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~15 minutes

Poem

In the warren of code, a hop and a bound,
Errors now clearer, with details profound.
Custom clients chirp with a structured reply,
No tangled responses, just truth—oh my!
With every new test, this rabbit will cheer,
For code that’s more friendly, robust, and clear!
🐇✨

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0ac7251 and c6e08e4.

📒 Files selected for processing (4)
  • src/errors/meilisearch-api-error.ts (1 hunks)
  • src/http-requests.ts (2 hunks)
  • src/types/types.ts (2 hunks)
  • tests/client.test.ts (3 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
src/errors/meilisearch-api-error.ts (1)
src/types/types.ts (1)
  • MeiliSearchErrorResponse (776-783)
🔇 Additional comments (9)
src/http-requests.ts (2)

231-242: Well-implemented structured response handling for custom HTTP clients.

The new logic correctly handles the structured CustomHttpClientResult format, properly distinguishing between success and failure cases. The error construction aligns well with the refactored MeiliSearchApiError class.


262-269: Improved error message handling for standard HTTP responses.

The conditional logic appropriately handles cases where there's no response body by providing a descriptive error message combining status code and status text, while still using the parsed response when available.

tests/client.test.ts (3)

11-22: Appropriate import additions for updated error handling.

The new imports support the enhanced test coverage for the refactored error handling system.


282-290: Correct implementation of the new CustomHttpClientResult interface.

The custom HTTP client properly returns the structured result format with success: true and the parsed response as the value.


310-339: Excellent test coverage for custom HTTP client failure scenarios.

This test comprehensively validates the error handling chain:

  • Properly simulates a failing custom HTTP client
  • Correctly implements the failure result structure
  • Verifies the complete error propagation from MeiliSearchApiError wrapped in MeiliSearchRequestError
  • Handles both parsed error responses and empty response bodies
src/types/types.ts (2)

46-58: Well-designed discriminated union type for HTTP client results.

The CustomHttpClientResult type provides:

  • Clear separation between success and failure cases using the success discriminant
  • Flexible value types that can handle both structured errors and simple strings
  • Comprehensive documentation explaining the expected structure and usage
  • Type safety through the discriminated union pattern

95-97: Improved type safety and documentation for httpClient configuration.

The updated type signature provides:

  • Specific return type instead of generic unknown
  • Clear expectations for implementers through the CustomHttpClientResult type
  • Enhanced documentation explaining the expected structure and behavior
src/errors/meilisearch-api-error.ts (2)

9-24: Excellent refactoring that decouples error handling from Response objects.

The new constructor design provides:

  • Flexibility to work with different HTTP client implementations
  • Support for both structured error responses and simple string messages
  • Proper preservation of detailed error information through the cause property
  • Cleaner separation of concerns by storing arbitrary details instead of coupling to Response

7-7: Appropriate use of flexible details property.

The details property with unknown type provides the necessary flexibility to store arbitrary error information from different HTTP client implementations while maintaining type safety.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

codecov bot commented Jul 25, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.02%. Comparing base (dacd4f3) to head (ee03c89).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1979   +/-   ##
=======================================
  Coverage   99.01%   99.02%           
=======================================
  Files          18       18           
  Lines        1418     1429   +11     
  Branches      299      304    +5     
=======================================
+ Hits         1404     1415   +11     
  Misses         14       14           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@flevi29 flevi29 marked this pull request as ready for review July 27, 2025 12:02
@flevi29 flevi29 requested review from brunoocasali and Strift August 1, 2025 07:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking-change The related changes are breaking for the users
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Decouple MeiliSearchApiError from Response, so it can be used with custom HTTP client
2 participants