Repository navigation
Conversation
BREAKING CHANGE: JSON responses with HTTP 200 and a top-level error key no longer raise SerpApiError. SerpApi returns searches with empty results this way (search_metadata.status Success), so search, search_archive, and extract now return them as a Hash with the message in results[:error]. SerpApiError is raised only for non-200 responses or when search_metadata.status is Error. Code that rescued SerpApiError to detect empty results must check results[:error] instead. Also set SerpApiError#serpapi_error and #search_id when using symbolize_names: false. Fixes serpapi#17 Co-authored-by: Claude Opus 5.5 (xhigh effort) <[email protected]>
Contributor
Author
|
Superseded by #42, opened from a branch on this repository. |
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.
Fixes #17.
Breaking change
JSON responses with HTTP
200and a top-levelerrorkey no longer raiseSerpApi::SerpApiError. This affectssearch,search_archive, andextract.SerpApi treats a search where the search engine returned no results as successful: HTTP
200,search_metadata.status: "Success", and anerrormessage such as "Google hasn't returned any results for this query." (see Status and Error Codes). The client treated anyerrorkey as a failure, so these searches raisedHTTP request failed with status: 200 OK. Because the error drops the response body, there was also no way to read archived searches with empty results throughsearch_archive, which is what #17 reports.200,status: "Success",error(empty results)SerpApiErrorresults[:error]200,status: "Error"Search failed with status: Error error: ...)200(400, 401, 429, 503, ...)Migration
Code that rescued
SerpApiErrorto detect empty results must checkresults[:error]instead:SerpApiErroris still raised for failed requests and failed searches, so existingrescueblocks keep working for real errors.Since this is breaking, the next release should be a major version (2.0.0).
version.rbisn't bumped in this PR.Changes
lib/serpapi/client.rb: raise only for a non-200status orsearch_metadata.status == "Error". The status check also catches failed searches if the Search Archive API returns them with HTTP200.SerpApiError#serpapi_errorand#search_idare now also set withsymbolize_names: false. Before, they were alwaysnilthere.**BREAKING:**entry.Testing
spec/serpapi/client/error_handling_spec.rbwith stubbed HTTP responses. It covers empty results fromsearchandsearch_archive, string keys, failed searches returned with HTTP200, and non-200responses. 4 of its 7 examples fail againstmaster.bundle exec rake lintpasses.