UNPKG

@afriex/core

Version:

HTTP client, configuration and typed errors for the Afriex Business API SDK

28 lines • 944 B
import { AfriexError } from "./AfriexError.js"; import { AfriexErrorCode } from "./ErrorCodes.js"; export class ApiError extends AfriexError { constructor(response, statusCode) { const errorMessage = response.details?.friendlyMessage || response.details?.errorMessage || response.error || response.message || "An API error occurred"; super(errorMessage); this.statusCode = statusCode; this.errorCode = response.code ?? (statusCode === 403 ? AfriexErrorCode.FORBIDDEN : undefined); this.details = response.details; this.response = response; } toJSON() { return { ...super.toJSON(), statusCode: this.statusCode, errorCode: this.errorCode, details: this.details, response: this.response, }; } } //# sourceMappingURL=ApiError.js.map