UNPKG

@planet-a/affinity-node

Version:
34 lines (33 loc) 1.05 kB
/** * Represents an error caused by an api call i.e. it has attributes for a HTTP status code * and the returned body object. * * Example * API returns a ErrorMessageObject whenever HTTP status code is not in [200, 299] * => ApiException(404, someErrorMessageObject) * */ export class ApiException extends Error { constructor(code, message, body, headers) { super("HTTP-Code: " + code + "\nMessage: " + message + "\nBody: " + JSON.stringify(body) + "\nHeaders: " + JSON.stringify(headers)); Object.defineProperty(this, "code", { enumerable: true, configurable: true, writable: true, value: code }); Object.defineProperty(this, "body", { enumerable: true, configurable: true, writable: true, value: body }); Object.defineProperty(this, "headers", { enumerable: true, configurable: true, writable: true, value: headers }); } }