UNPKG

channelape-sdk

Version:
50 lines 1.71 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); class ChannelApeError extends Error { constructor(message, response, uri, apiErrors) { super(getMessage()); this.response = response; this.apiErrors = apiErrors; function getMessage() { let ret = message; if (apiErrors.length > 0) { const messageParts = apiErrors.map(getApiError).join('\n'); ret += `\n${messageParts}`; } let method; let statusCode; let statusMessage; if (typeof response === 'undefined') { method = ''; statusCode = 0; statusMessage = ''; } else { method = typeof response.method === 'undefined' ? '' : response.method; statusCode = typeof response.statusCode === 'undefined' ? 0 : response.statusCode; statusMessage = typeof response.statusMessage === 'undefined' ? '' : response.statusMessage; } return `${method} ${uri} Status: ${statusCode} ${statusMessage} Response Body: ${ret}`; } function getApiError(apiError, index) { return `Code: ${apiError.code} Message: ${apiError.message}`; } } get Response() { if (this.response === undefined) { return { statusCode: -1, statusMessage: 'There was an error with the API' }; } return this.response; } get ApiErrors() { return this.apiErrors; } } exports.default = ChannelApeError; //# sourceMappingURL=ChannelApeError.js.map