UNPKG

@trophyso/node

Version:
40 lines (39 loc) 1.44 kB
"use strict"; // This file was auto-generated by Fern from our API Definition. Object.defineProperty(exports, "__esModule", { value: true }); exports.TrophyApiError = void 0; const json_1 = require("../core/json"); class TrophyApiError extends Error { constructor({ message, statusCode, body, rawResponse, cause, }) { super(buildMessage({ message, statusCode, body })); Object.setPrototypeOf(this, new.target.prototype); if (Error.captureStackTrace) { Error.captureStackTrace(this, this.constructor); } this.name = "TrophyApiError"; this.statusCode = statusCode; this.body = body; this.rawResponse = rawResponse; if (cause != null) { this.cause = cause; } } get requestId() { var _a, _b, _c; return (_c = (_b = (_a = this.rawResponse) === null || _a === void 0 ? void 0 : _a.headers) === null || _b === void 0 ? void 0 : _b.get("x-request-id")) !== null && _c !== void 0 ? _c : undefined; } } exports.TrophyApiError = TrophyApiError; function buildMessage({ message, statusCode, body, }) { const lines = []; if (message != null) { lines.push(message); } if (statusCode != null) { lines.push(`Status code: ${statusCode.toString()}`); } if (body != null) { lines.push(`Body: ${(0, json_1.toJson)(body, undefined, 2)}`); } return lines.join("\n"); }