UNPKG

@ballin-team/paysync-nubank

Version:

<h1 align="center"> <img src="https://docs.nupaybusiness.com.br/images/logotipo.png" alt="NuPay for Business" /> </h1>

30 lines (29 loc) 955 B
import { AxiosError } from 'axios'; export class NubankApiError extends Error { path; status; details; constructor(input) { let message = 'unknown error'; if (typeof input.isAuthentic === 'boolean' && !input.isAuthentic) { message = 'Unauthenticated message'; } if (input.data instanceof Error) message = input.data.message; super(message); Object.setPrototypeOf(this, NubankApiError.prototype); this.name = 'NubankApiError'; this.path = input.path; if (input.data instanceof AxiosError) { const data = input.data; const response = data.response?.data; this.status = response?.status; this.message = response?.message || 'unknown error'; this.details = response?.details; } else { this.details = input.data; } console.error(this); } }