UNPKG

box-node-sdk

Version:

Official SDK for Box Platform APIs

62 lines 2.3 kB
import { GeneratedCodeError } from '../internal/errors.js'; import { utilLib } from '../internal/utils.js'; import { DataSanitizer } from '../internal/logging.js'; export class BoxSdkError extends GeneratedCodeError { timestamp; error; constructor(fields) { super(fields); this.name = 'BoxSdkError'; this.timestamp = fields.timestamp; this.error = fields.error; Object.setPrototypeOf(this, BoxSdkError.prototype); } } export class BoxApiError extends BoxSdkError { requestInfo; responseInfo; dataSanitizer = new DataSanitizer({}); constructor(fields) { super(fields); this.name = 'BoxApiError'; this.requestInfo = fields.requestInfo; this.responseInfo = fields.responseInfo; if (fields.dataSanitizer) { this.dataSanitizer = fields.dataSanitizer; } Object.setPrototypeOf(this, BoxApiError.prototype); } [utilLib.inspect.custom]() { return this.toString(); } toString() { return JSON.stringify(this.toJSON(), null, 2); } toJSON() { return { name: this.name, message: this.message, timestamp: this.timestamp, error: this.error, requestInfo: { method: this.requestInfo.method, url: this.requestInfo.url, queryParams: this.requestInfo.queryParams, headers: this.dataSanitizer.sanitizeHeaders(this.requestInfo.headers), body: typeof this.requestInfo.body === 'string' ? this.dataSanitizer.sanitizeStringBody(this.requestInfo.body, this.requestInfo.contentType) : this.requestInfo.body, }, responseInfo: { statusCode: this.responseInfo.statusCode, headers: this.dataSanitizer.sanitizeHeaders(this.responseInfo.headers), body: this.dataSanitizer.sanitizeBody(this.responseInfo.body), code: this.responseInfo.code, contextInfo: this.responseInfo.contextInfo, requestId: this.responseInfo.requestId, helpUrl: this.responseInfo.helpUrl, }, }; } } //# sourceMappingURL=errors.js.map