Error contract

How every SDK behaves when configuration is wrong, the network fails or a provider is down, and the error codes sign-in and verification can raise.

On this page

Sponsorkit must never break your app. A sponsorship check is a nice-to-have, so an outage at Sponsorkit, GitHub or Open Collective, a flaky network or a rate limit must not crash a CLI or blank a page. Every SDK behaves the same way, and a shared conformance suite enforces it.

What getFinancialContribution() does#

SituationBehaviour
No targets or a malformed targetThrows invalid_config, from the constructor.
A target that doesn't exist (only with the development check on)Throws invalid_config on the first call.
Not signed inSigned-out result, no network call.
session_invalid (expired or tampered token)Clears the token and cache, returns the signed-out result.
One provider unavailableMerges that provider's cached contributions, stale: true.
Network error, timeout, 5xx, rate limitedReturns the cache (fromCache: true, stale: true), or an empty signed-in result with stale: true. Never throws.
SPONSORKIT_DISABLE=1No network or disk. disabled: true; signIn and openCheckout reject with disabled.

So the only error a check can raise is invalid_config, which you see during development, not in your users' hands. In Go and Rust the check returns an error value for the same reason; the result is always usable otherwise. In .NET, cancelling its CancellationToken throws OperationCanceledException as usual.

Every HTTP request has a 30-second timeout (requestTimeout; 0 disables it, except in Go, where the zero value means the default and sponsorkit.NoRequestTimeout disables it). A timeout counts as a network error: checks serve the cache, while sign-in fails with network_error.

Error codes#

Everything an SDK throws is a SponsorkitError (Go: *sponsorkit.Error, Rust: sponsorkit::Error) with one of these codes:

CodeRaised byWhen
invalid_configConstructor, any callMissing or malformed targets or options; a target that doesn't exist (development check); signIn() couldn't save the session or signOut() couldn't clear it.
disabledsignIn, openCheckoutSPONSORKIT_DISABLE is set.
popup_blockedsignIn, openCheckout (browser SDK only)The popup was blocked and no returnTo fallback is set. openCheckout opens its window before anything else, so it can raise this even when the user is already signed in.
access_deniedsignIn, openCheckout (sign-in phase)The supporter declined at GitHub or Open Collective.
invalid_state, provider_errorsignIn, openCheckout (sign-in phase)The sign-in expired or failed at the provider.
invalid_codesignIn, openCheckout (sign-in phase)The API rejected the sign-in code (expired, or a mistyped paste-back code).
cancelledsignIn, openCheckout (sign-in phase)The popup was closed or no paste-back code was entered. signIn also raises it when your cancellation fires; openCheckout resolves { status: "unknown" } for that instead.
timeoutsignIn, openCheckout (sign-in phase)signInTimeout (default 5 minutes) passed. openCheckout's own timeout bounds only the polling phase and resolves { status: "unknown" }.
network_errorsignIn, openCheckout (sign-in phase), verifySessionThe API couldn't be reached, timed out, or answered 5xx, 429 or something unexpected. Carries retryAfter when the API sent Retry-After.
session_invalid, targets_mismatchverifySession onlyThe token is invalid or expired, or was issued for other targets.

openCheckout() signs the user in first when they aren't signed in yet, and raises the sign-in codes only during that phase. It doesn't fail when nothing is detected afterwards: a polling timeout or cancellation resolves { status: "unknown" }. All five SDKs behave the same way. "Your cancellation" is the signal (JavaScript), CancellationToken (.NET), cancel event (Python), context.Context (Go, including a deadline on it) or cancel token (Rust) passed to the call. A closed popup, an empty paste-back code or an expired signInTimeout still make openCheckout raise cancelled or timeout. The errors and offline guide has the full table with what to do about each code.

Handling sign-in errors#

Most apps only need to tell "the user walked away" from "try again later":

try {
  await sk.signIn();
} catch (e) {
  if (isSponsorkitError(e, "cancelled") || isSponsorkitError(e, "timeout")) return; // the user walked away
  if (e instanceof SponsorkitError && e.code === "network_error") {
    console.error(`Sponsorkit is unreachable; try again in ${e.retryAfter ?? 60} s`);
    return;
  }
  throw e;
}

Go also offers sponsorkit.ErrorCodeOf(err), which returns the code of any wrapped *sponsorkit.Error.

Turning Sponsorkit off#

Set SPONSORKIT_DISABLE=1 (any non-empty value except 0 or false) and the SDK does nothing: no network, no disk, disabled: true results, and nags never show. It's a good switch to document for your users, for air-gapped machines or anyone who'd rather not see sponsorship features. It beats mock mode.