channelape-sdk
Version:
A client for interacting with ChannelApe's API
55 lines • 2.06 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
class ChannelApeError extends Error {
constructor(message, response, uri, apiErrors) {
super(getMessage());
this.apiErrors = apiErrors;
if (typeof response === 'undefined') {
this.responseStatusCode = -1;
this.responseStatusMessage = 'There was an error with the API';
}
else {
this.responseStatusCode = response.status == null ? -1 : response.status;
this.responseStatusMessage = response.statusText == null
? 'There was an error with the API' : response.statusText;
}
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' || response.config === undefined) {
method = '';
statusCode = 0;
statusMessage = '';
}
else {
method = typeof response.config.method === 'undefined' ? '' : response.config.method;
statusCode = typeof response.status === 'undefined' ? 0 : response.status;
statusMessage = typeof response.statusText === 'undefined' ? '' : ` ${response.statusText}`;
}
return `${method} ${uri}
Status: ${statusCode}${statusMessage}
Response Body:
${ret}`;
}
function getApiError(apiError, index) {
return `Code: ${apiError.code} Message: ${apiError.message}`;
}
}
get Response() {
return {
statusCode: this.responseStatusCode,
statusMessage: this.responseStatusMessage
};
}
get ApiErrors() {
return this.apiErrors;
}
}
exports.default = ChannelApeError;
//# sourceMappingURL=ChannelApeError.js.map