@afriex/core
Version:
HTTP client, configuration and typed errors for the Afriex Business API SDK
128 lines • 8.19 kB
JavaScript
/**
* `code` values returned by the Afriex Business API's `ErrorResponse.code` field.
* Kept in sync with the values documented across the OpenAPI spec's error examples.
*
* The set is not closed: the API can return codes that are not listed here, so
* compare `ApiError.errorCode` against these constants rather than assuming
* every response carries one of them.
*/
export const AfriexErrorCode = {
// Authentication
/** 401. Also returned when the key lacks the permission the endpoint needs. */
AUTHENTICATION_ERROR: "AUTHENTICATION_ERROR",
/**
* 403. Set by the SDK when an endpoint is not available in the current
* environment: those responses carry `{ message }` and no `code` of their own.
*/
FORBIDDEN: "FORBIDDEN",
// Validation
VALIDATION_ERROR: "VALIDATION_ERROR",
/** 400. Observed in the sandbox, e.g. for an unsupported `x-api-version`. */
BAD_REQUEST_ERROR: "BAD_REQUEST_ERROR",
INVALID_USER_DATA: "INVALID_USER_DATA",
INVALID_BUSINESS_CUSTOMER_REQUEST: "INVALID_BUSINESS_CUSTOMER_REQUEST",
INVALID_BUSINESS_CUSTOMER_ID: "INVALID_BUSINESS_CUSTOMER_ID",
INVALID_BUSINESS_TRANSACTION_REQUEST: "INVALID_BUSINESS_TRANSACTION_REQUEST",
INVALID_BUSINESS_TRANSACTION_ID: "INVALID_BUSINESS_TRANSACTION_ID",
/** 400. Observed in the sandbox on POST /payment-method. */
INVALID_BUSINESS_PAYMENT_METHOD_REQUEST: "INVALID_BUSINESS_PAYMENT_METHOD_REQUEST",
INVALID_BUSINESS_PAYMENT_METHOD_ID: "INVALID_BUSINESS_PAYMENT_METHOD_ID",
INVALID_BUSINESS_POOL_ACCOUNT_REQUEST: "INVALID_BUSINESS_POOL_ACCOUNT_REQUEST",
/**
* 400. Observed in the sandbox on the payment batch endpoints, e.g. for a
* recipient or session that is not in the batch.
*/
INVALID_BUSINESS_PAYMENT_BATCH_REQUEST: "INVALID_BUSINESS_PAYMENT_BATCH_REQUEST",
INVALID_KYC_DOCUMENT_TYPE: "INVALID_KYC_DOCUMENT_TYPE",
/** 400. The channel is not supported by the endpoint, e.g. institution lookup. */
INVALID_TRANSACTION_CHANNEL: "INVALID_TRANSACTION_CHANNEL",
/** The one-time password submitted to authorize a transaction was wrong. */
OTP_INCORRECT: "OTP_INCORRECT",
/** 400. Observed in the sandbox when the amount is below the corridor minimum. */
TRANSACTION_AMOUNT_TOO_SMALL: "TRANSACTION_AMOUNT_TOO_SMALL",
// Conflicts
/**
* 409. A transaction with the same idempotency key or reference, or a
* checkout session with the same merchantReference, already exists. The
* original is not replayed: look it up instead of retrying.
*/
DUPLICATE_REQUEST: "DUPLICATE_REQUEST",
/** 409. `details.data.customerId` carries the existing customer's id. */
EMAIL_ALREADY_EXISTS: "EMAIL_ALREADY_EXISTS",
/** 409. `details.data.customerId` carries the existing customer's id. */
PHONE_NUMBER_ALREADY_EXISTS: "PHONE_NUMBER_ALREADY_EXISTS",
// Not found
/** 404. Observed in the sandbox for a payment batch that does not exist. */
NOT_FOUND_ERROR: "NOT_FOUND_ERROR",
BUSINESS_CUSTOMER_NOT_FOUND: "BUSINESS_CUSTOMER_NOT_FOUND",
BUSINESS_TRANSACTION_NOT_FOUND: "BUSINESS_TRANSACTION_NOT_FOUND",
BUSINESS_PAYMENT_METHOD_NOT_FOUND: "BUSINESS_PAYMENT_METHOD_NOT_FOUND",
BUSINESS_NOT_FOUND: "BUSINESS_NOT_FOUND",
USER_NOT_FOUND: "USER_NOT_FOUND",
PAYMENT_METHOD_NOT_FOUND: "PAYMENT_METHOD_NOT_FOUND",
TRANSACTION_PROCESSOR_NOT_FOUND: "TRANSACTION_PROCESSOR_NOT_FOUND",
/** 404. Observed in the sandbox when no processor serves the channel and country. */
PROCESSOR_NOT_FOUND: "PROCESSOR_NOT_FOUND",
// Business logic / limits
VIRTUAL_ACCOUNT_LIMIT_REACHED: "VIRTUAL_ACCOUNT_LIMIT_REACHED",
/** 403. A virtual account for a customer can only be NGN. */
UNSUPPORTED_VIRTUAL_ACCOUNT_CURRENCY: "UNSUPPORTED_VIRTUAL_ACCOUNT_CURRENCY",
/** 403. The currency needs a compliance-approved application first. */
VIRTUAL_ACCOUNT_PENDING_COMPLIANCE_REVIEW: "VIRTUAL_ACCOUNT_PENDING_COMPLIANCE_REVIEW",
/** 429. The code the API sends when a rate limit is hit. */
RATE_LIMIT_ERROR: "RATE_LIMIT_ERROR",
/**
* @deprecated The API sends `RATE_LIMIT_ERROR`. Kept so existing comparisons
* keep compiling; it never matches a response.
*/
RATE_LIMIT_EXCEEDED: "RATE_LIMIT_EXCEEDED",
// Server errors
INTERNAL_SERVER_ERROR: "INTERNAL_SERVER_ERROR",
/**
* 503. An upstream processor failed or timed out, or the API is momentarily
* offline. Retry with backoff and honour `Retry-After`.
*/
EXTERNAL_REQUEST_ERROR: "EXTERNAL_REQUEST_ERROR",
// Unknown (client-side fallback; not returned by the API)
UNKNOWN_ERROR: "UNKNOWN_ERROR",
};
export const ERROR_CODE_MESSAGES = {
[]: "Authentication failed, or the API key lacks the permission this endpoint needs",
[]: "The endpoint is not available in this environment",
[]: "Request failed schema validation",
[]: "The request could not be processed",
[]: "Invalid user data",
[]: "Invalid business customer request",
[]: "Invalid business customer id",
[]: "Invalid business transaction request",
[]: "Invalid business transaction id",
[]: "Invalid business payment method request",
[]: "Invalid business payment method id",
[]: "Invalid business pool account request",
[]: "Invalid business payment batch request",
[]: "Invalid KYC document type or value",
[]: "The channel is not supported by this endpoint",
[]: "The one-time password is incorrect",
[]: "The transaction amount is below the minimum",
[]: "A request with the same idempotency key or reference already exists",
[]: "A customer with this email already exists",
[]: "A customer with this phone number already exists",
[]: "The resource was not found",
[]: "Business customer not found",
[]: "Business transaction not found",
[]: "Business payment method not found",
[]: "Business not found",
[]: "User not found",
[]: "Payment method not found",
[]: "No transaction processor available for this request",
[]: "No processor available for this channel and country",
[]: "Virtual account limit reached for this customer and currency",
[]: "A virtual account for a customer can only be created in NGN",
[]: "Virtual accounts in this currency are pending compliance review",
[]: "Too many requests, please try again later",
[]: "Too many requests, please try again later",
[]: "It's not you, it's us, please reach out to support",
[]: "An upstream service is temporarily unavailable, please retry",
[]: "Unknown error",
};
//# sourceMappingURL=ErrorCodes.js.map