| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
execute() and uploadImage() rejected with the raw response body string when SerpApi returned a non-200 status code. The rejection had no HTTP status code, was not an Error, and lost the stack trace, so callers could not branch on the failure kind or log where it came from. Add an HTTPError class exposing statusCode and the raw body, with the message set to the error field of a JSON response when present, and reject with it in both request paths. This matches the structured HTTP errors already exposed by the serpapi-python (HTTPError.status_code) and serpapi-ruby (SerpApiError#response_status) SDKs.
|
Hi, just following up on this when you get a chance. The branch is up to date and checks are green. If it looks good from your side, it should be ready to merge. Happy to make any changes if needed. Thanks! |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Problem
execute() and uploadImage() in src/utils.ts reject with the raw response body string when SerpApi responds with a non-200 status code:
A rejected bare string is not an Error: it has no HTTP status code, no stack trace, and cannot be distinguished from other failures with instanceof. This makes it hard for callers to branch on the failure kind (for example, a 401 invalid key versus a 429 rate limit) or to log where the rejection came from.
Before:
Solution
Add an HTTPError class in src/errors.ts exposing statusCode and the raw body. The message is set to the error field of a JSON response when present, and falls back to a status-code message for non-JSON bodies. Both request paths now reject with it.
After:
This also matches the structured HTTP errors already exposed by the other SerpApi SDKs: serpapi-python's HTTPError.status_code and serpapi-ruby's SerpApiError#response_status.
Validation
Notes