UNPKG

sendingnetwork-bot-sdk

Version:
40 lines (35 loc) 996 B
/** * Represents an HTTP error from the SDN server. * @category Error handling */ export class SDNError extends Error { /** * The SDN error code */ public readonly errcode: string; /** * Optional human-readable error message. */ public readonly error: string; /** * If rate limited, the time in milliseconds to wait before retrying the request */ public readonly retryAfterMs?: number; /** * Creates a new SDN Error * @param body The error body. * @param statusCode The HTTP status code. */ constructor(public readonly body: { errcode: string, error: string, retry_after_ms?: number }, public readonly statusCode: number) { super(); this.errcode = body.errcode; this.error = body.error; this.retryAfterMs = body.retry_after_ms; } /** * Developer-friendly error message. */ public get message() { return `${this.errcode}: ${this.error}`; } }