Skip to content

Add error handling for callback usage - #43

Open
tarunspandit wants to merge 1 commit into
serpapi:masterfrom
tarunspandit:codex/serpapi-callback-errors
Open

Add error handling for callback usage#43
tarunspandit wants to merge 1 commit into
serpapi:masterfrom
tarunspandit:codex/serpapi-callback-errors

Conversation

@tarunspandit

Copy link
Copy Markdown

Summary

  1. Add optional error callbacks to getJson and getHtml for both supported call forms.
  2. Preserve every existing success callback signature and the returned Promise rejection behavior.
  3. Document callback error handling and add the change to the unreleased changelog.

Closes #14.

Compatibility

Existing callback and Promise calls are unchanged. The new callback is the final optional argument:

getJson(parameters, onSuccess, onError);
getJson(engine, parameters, onSuccess, onError);
getHtml(parameters, onSuccess, onError);
getHtml(engine, parameters, onSuccess, onError);

The original Promise is still returned and still rejects. Attaching an error callback also lets callback only callers observe failures without creating an unhandled rejection.

Verification

  1. npx --yes deno@2.4.3 fmt --check
  2. npx --yes deno@2.4.3 lint
  3. npx --yes deno@2.4.3 task test
  4. npx --yes deno@2.4.3 task npm
  5. Generated ESM and CommonJS declarations include both overloads and the optional error callback.
  6. Generated ESM and CommonJS packages pass callback only failure checks under Node with strict unhandled rejection handling.

The test suite reports 9 passing suites with 39 passing steps, no failures, and 2 live API suites skipped because no test API key was supplied.

Repository environment note

Current master has unrelated compatibility failures under the newest Deno release, including the existing timeout handle typing in src/utils.ts and newer lint treatment of inline URL imports. The verification above uses Deno 2.4.3, which passes current master and this change.

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.

Error handling for callback usage

1 participant