Errors

The NahuPay API uses conventional HTTP status codes to indicate success or failure. Errors include a machine-readable code and a human-readable message.

Error format

{
  "error": {
    "code":    "invalid_amount",
    "message": "Amount must be a positive integer in ETB cents.",
    "param":   "amount"   // present when the error is tied to a specific field
  }
}
FieldTypeDescription
codestringMachine-readable error code — safe to switch on.
messagestringHuman-readable description. Do not display to end users.
paramstring | nullThe request field that caused the error, if applicable.

Error codes

CodeStatusDescription
invalid_amount400Amount must be a positive integer in ETB cents.
invalid_currency400Only ETB is supported.
invalid_method400Unknown payment method identifier.
missing_param400A required parameter is missing. See error.param.
invalid_url400success_url or cancel_url is not a valid HTTPS URL.
authentication_failed401API key is missing, malformed, or revoked.
account_not_verified403Live key used but KYB is not complete.
payment_not_found404No payment with that ID exists on this account.
idempotency_conflict409Idempotency key reused with different parameters.
rate_limit_exceeded429Too many requests. Check the Retry-After header.
payment_gateway_error502Upstream provider error. Retry after a short delay.
internal_error500Unexpected server error. Contact support if it persists.

Handling errors in code

All SDKs surface errors as typed exceptions:

import NahuPay, { NahuPayError } from 'nahupay';try {const payment = await client.payments.create({ amount: -1, currency: 'ETB' });} catch (err) {if (err instanceof NahuPayError) {console.log(err.code);       // "invalid_amount"console.log(err.statusCode);  // 400console.log(err.param);       // "amount"}}