Skip to content
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

Enhanced Error Handling with Detailed Payload Information #259

Merged
merged 2 commits into from
Jan 28, 2025

Conversation

tharropoulos
Copy link
Contributor

Change Summary

What is this?

This enhancement improves error handling across the Typesense client library by providing more detailed error information when things go wrong. This is particularly valuable for debugging import operations and API calls, as it now includes the complete context of what was being attempted when the error occurred. By exposing more detailed error information, developers can more quickly diagnose and fix issues in their applications.

Changes

Added Features:

  1. New Properties in TypesenseError:

    • Added httpBody and httpStatus properties to capture complete HTTP response context
    • Constructor now accepts these additional parameters for better error context
  2. Enhanced ImportError in ImportError.ts:

    • Added payload property containing comprehensive import operation details:
      • Original document data (documentsInJSONLFormat)
      • Import options used (options)
      • Failed items count (failedItems)
      • Success count (successCount)

Code Changes:

  1. In ApiCall.ts:

    • Updated requestOptions type to AxiosRequestConfig<string> for better type safety
    • Modified customErrorForResponse to include request body in error creation
    • Updated error handling in request processing to pass request data to error objects
  2. In Documents.ts:

    • Enhanced import error handling to include detailed payload information
    • Updated error messages for failed imports with more context
    • Added additional context for Node.js object key limit errors

Documentation Updates:

  1. Type Definitions:
    • Added ImportErrorPayload interface to define the structure of import error details
    • Updated error-related type definitions for better TypeScript integration

Context

This change is particularly important for developers working with large-scale data imports and complex API interactions, as it provides much more context when debugging issues. The enhanced error information makes it easier to:

  • Identify exactly which documents failed during bulk imports
  • Understand the complete context of API call failures
  • Debug issues related to request payloads and responses

PR Checklist

- Add `httpBody` and `httpStatus` to `TypesenseError` constructor
- Extend `ImportError` with detailed payload information for failed imports
- Update `ApiCall` to include request data in error messages
- Add type annotation for `AxiosRequestConfig<string>`
@jasonbosco jasonbosco merged commit b67ded8 into typesense:master Jan 28, 2025
1 check passed
@jasonbosco
Copy link
Member

This is now published in v2.0.0-15

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