Skip to Content
Errors

Errors

Two different kinds of failure

Request errors — your API call itself was wrong (bad phone number, expired key, rate limit) — throw a typed error synchronously:

import { ValidationError, RateLimitError, VectaPayError } from "@vectapay/sdk"; try { await vectapay.payments.collect({ /* ... */ }); } catch (error) { if (error instanceof ValidationError) { console.log(error.details); // field-level messages, when the backend returns them } else if (error instanceof RateLimitError) { console.log(`retry after ${error.retryAfterSeconds}s`); } else if (error instanceof VectaPayError) { console.log(error.statusCode, error.message); } }
ClassStatusMeaning
ValidationError400, 422The request itself is malformed.
AuthenticationError401Missing, invalid, or wrong-environment API key.
PermissionError403Valid key, but missing role/plan permission.
NotFoundError404No such payment/payout/resource.
ConflictError409An idempotencyKey was reused for a request with different parameters.
RateLimitError429Retried automatically; check the retry-after property if you’ve disabled retries. Also returned when a test-mode prompt budget is used up.
ServerError5xxRetried automatically.
NetworkError / TimeoutError—No response was received at all.

Every error class in every SDK catches most-specific-first — order your catch/except blocks that way, ending with the base VectaPayError/VectaPayError class as a catch-all.

Python only: PermissionError and TimeoutError are also names of built-in Python exceptions (OSError subclasses). from vectapay import PermissionError, TimeoutError shadows them in that scope — fine inside a small handler, but if a file already relies on the built-in meaning (catching an OS-level permission or socket timeout error), import these two under an alias instead: from vectapay import PermissionError as VectaPayPermissionError.

Environment and test-mode errors

These are request errors specific to which key and which mode you are using. None of them come from the customer — they mean the call itself was aimed at the wrong place.

StatusMessageCause
401API key environment mismatch. Required: LIVE, Got: TEST.A pk_test_ key was sent to a live-only route — payouts, refunds, payment retries, or batch operations. Create a pk_live_ key, or take the call out of your test suite.
400Verify the phone you want to test with first: open Developer → Testing and send the KES 10 verification prompt.A test-mode collect() before any phone is verified.
400Test payments can only be sent to your verified test phone (the number ending in 678). …A test-mode collect() to a number that is not the verified one. The message shows the last three digits of the verified number.
400Test payments always run on our test line. Remove providerAccountId from the request.A test-mode collect() with a providerAccountId that isn’t the test line. Remove it — test mode always picks the line for you.
429Too many test prompts have been sent. Try again in about N minutes.A test-mode prompt budget is used up. Read retryAfterSeconds from the error body and wait — see Testing for the budgets.

Payment outcome failures — the request succeeded, but the payment didn’t (the customer cancelled, insufficient funds) — arrive later, on the payment record or a payment.failed webhook, as a FailureCode. This is the taxonomy to branch your business logic on — see Events for a worked example per language.

FailureCode reference

CodeWhat happenedWhat to tell the customer
CUSTOMER_CANCELLEDThey dismissed the prompt on their phone.Ask them to try again.
CUSTOMER_TIMEOUTThey didn’t enter their PIN in time.Send the request again.
INSUFFICIENT_FUNDSNot enough money in their account.Ask them to top up and retry.
INVALID_ACCOUNTThe phone number or account isn’t valid.Confirm the details and try again.
INVALID_AMOUNTThis amount couldn’t be processed.Check the amount and try again.
LIMIT_EXCEEDEDAbove the limit for a single payment.Split it into smaller payments.
DUPLICATE_PAYMENTA matching payment already exists.Check your payments list first.
SUBSCRIBER_BUSYThe customer’s phone has another M-Pesa transaction in progress.Ask them to finish or cancel it, then retry in a minute.
PROVIDER_UNAVAILABLEThe provider isn’t responding right now.Nothing to do — it’ll be retried.
PROVIDER_REJECTEDThe provider declined this payment.Try a different payment method.
AUTHENTICATION_FAILEDVectaPay couldn’t connect to your payment account.Check your payment method setup.
NETWORK_TIMEOUTThe connection to the provider timed out.Nothing to do — it’ll be retried.
UNKNOWNUnclassified failure.Contact support if this keeps happening.

This is the same taxonomy shown to merchants in plain language in the dashboard — see Why did a payment fail? if you’re building a merchant-facing surface of your own and want copy to match.

Last updated on