import { Mensaje } from './types'; export interface DgiiApiErrorContext { /** Resource path that was requested, e.g. `/TesteCF/autenticacion/...`. */ resource?: string; /** HTTP method used for the request. */ method?: string; /** Base url used for the request. */ baseURL?: string; /** * Message to use when DGII did not return any description in the body. * Defaults to the HTTP status / axios message. */ fallbackMessage?: string; } interface DgiiApiErrorOptions extends DgiiApiErrorContext { status?: number; statusText?: string; code?: string; data?: unknown; mensajes?: Mensaje[]; cause?: unknown; } /** * Extract the human readable error DGII sent in the response body. * * The DGII services are inconsistent: an authentication failure comes back as * a bare string (`"El RNC ... del certificado no está delegado para * realizar transaciones."`), other endpoints answer with `{ mensajes: [...] }`, * with an ASP.NET `ProblemDetails`/`ModelState` payload, or with an HTML error * page. Every one of those shapes is reduced to a single string here so the * caller never has to fall back to the generic axios message. */ export declare const extractDgiiErrorMessage: (data: unknown, seen?: WeakSet) => string | undefined; /** * Error thrown by every `RestApi` method when a DGII request fails. * * `message` carries the description DGII actually sent whenever the service * provided one, so logging `error.message` no longer reports the opaque * `Request failed with status code 400`. The raw payload, the HTTP status and * the requested resource stay available for structured logging. */ export declare class DgiiApiError extends Error { /** HTTP status returned by DGII, when the request reached the service. */ readonly status?: number; /** HTTP status text returned by DGII. */ readonly statusText?: string; /** Axios error code (`ECONNABORTED`, `ETIMEDOUT`, ...) for transport errors. */ readonly code?: string; /** Resource that was requested. */ readonly resource?: string; /** HTTP method used for the request. */ readonly method?: string; /** Base url used for the request. */ readonly baseURL?: string; /** Raw response body as received from DGII. */ readonly data?: unknown; /** `mensajes` returned by DGII, when the body carried them. */ readonly mensajes?: Mensaje[]; constructor(message: string, options?: DgiiApiErrorOptions); /** * Errors serialize to `{}` with `JSON.stringify`, which is how these values * end up persisted by the consumers (tracking records, CloudWatch logs), so * the useful fields are exposed explicitly. */ toJSON(): { name: string; message: string; status: number | undefined; statusText: string | undefined; code: string | undefined; resource: string | undefined; method: string | undefined; mensajes: Mensaje[] | undefined; data: unknown; }; } /** * Normalize anything thrown by axios (or by our own code) into a * `DgiiApiError` carrying the real DGII description. */ export declare const toDgiiApiError: (err: unknown, context?: DgiiApiErrorContext) => DgiiApiError; export default DgiiApiError;