[exa-js]: robust error handling with retries for transient failures#140
Open
devin-ai-integration[bot] wants to merge 1 commit intomasterfrom
Open
[exa-js]: robust error handling with retries for transient failures#140devin-ai-integration[bot] wants to merge 1 commit intomasterfrom
devin-ai-integration[bot] wants to merge 1 commit intomasterfrom
Conversation
…ilures - Wrap fetchImpl in try/catch to convert network errors (TypeError: fetch failed) into ExaError - Safely parse JSON on error path: when server returns HTML (e.g. 502 load balancer page), catch SyntaxError and include truncated response body in error message - Safely parse JSON on success path for the same reason - Add automatic retry with exponential backoff for transient failures (429, 502, 503, 504) and network errors (up to 2 retries) Co-Authored-By: Yi Yang <yi@exa.ai>
Contributor
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
[exa-js]: robust error handling with retries for transient failures
Summary
Addresses customer-reported
SyntaxError: Unexpected token '<'andTypeError: fetch failederrors on websets API calls (websets.get,websets.create,websets.items,websets.searches.create).The root cause: the
request()method insrc/index.tshad no protection against:response.json()throwsSyntaxErrorinstead of producing a usefulExaErrorfetch()throwingTypeError: fetch failedpropagated raw instead of asExaErrorChanges to the
request()method:fetchImpl()in try/catch → network errors becomeExaErrorwithstatusCode: 0response.json()on both error and success paths → HTML/non-JSON bodies produce descriptiveExaErrorwith truncated body previewReview & Testing Checklist for Human
websets.createandwebsets.searches.creatego through this path — retrying these on 502/503 could create duplicate resources. Consider whether retries should be limited to GET/idempotent methods, or if the websets API is idempotent by design.response.json()fails, the catch block callsresponse.text(). After.json()partially consumes the body stream,.text()may return empty string (handled by.catch(() => "")) — so error messages may sayNon-JSON response ()with no body preview. Verify this is acceptable or consider reading body as text first, then parsing.rawRequest()not updated: Onlyrequest()gets retries/error wrapping.rawRequest()returns rawResponseand is unchanged — verify no callers depend on it having similar resilience.DEFAULT_MAX_RETRIES=2andINITIAL_RETRY_DELAY_MS=1000are module-level constants. Users cannot disable or tune retries. Consider if this needs to be configurable via constructor options.Notes
Link to Devin run: https://app.devin.ai/sessions/a7d384b145ae4fa58ee98bf15d751535
Requested by: Yi Yang