@afriex/core
Version:
HTTP client, configuration and typed errors for the Afriex Business API SDK
53 lines • 1.82 kB
TypeScript
import { AfriexError } from "./AfriexError.js";
/**
* Caller-safe context attached to an API error. `friendlyMessage` is
* safe to display to end users; `errorMessage` is the technical detail.
*/
export interface ApiErrorDetails {
errorMessage?: string;
friendlyMessage?: string;
data?: {
customerId?: string;
[key: string]: unknown;
};
[key: string]: unknown;
}
/**
* Shape of the Afriex Business API error body: `{ code, error, details }`,
* where `error` is a human-readable string (not an object).
*
* One family of responses does not follow it: an endpoint that is not
* available in the current environment (a sandbox-only endpoint called in
* production, for example) answers 403 with `{ message: "Not allowed" }` and
* no `code`.
*/
export interface ApiErrorResponse {
code?: string;
error?: string;
details?: ApiErrorDetails;
/** Present on the 403 an environment-restricted endpoint returns. */
message?: string;
}
export declare class ApiError extends AfriexError {
readonly statusCode: number;
/**
* The API's machine-readable `code`. A 403 that carries no code of its own is
* reported as `AfriexErrorCode.FORBIDDEN`, so an environment restriction can
* be told apart from a rejected key, which answers 401.
*/
readonly errorCode?: string;
readonly details?: ApiErrorDetails;
readonly response: ApiErrorResponse;
constructor(response: ApiErrorResponse, statusCode: number);
toJSON(): {
name: string;
message: string;
timestamp: Date;
stack: string | undefined;
statusCode: number;
errorCode: string | undefined;
details: ApiErrorDetails | undefined;
response: ApiErrorResponse;
};
}
//# sourceMappingURL=ApiError.d.ts.map