trade360-nodejs-sdk
Version:
LSports Trade360 SDK for Node.js
43 lines • 2.07 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.HttpResponseError = void 0;
const lodash_1 = require("lodash");
const base_error_1 = require("./base.error");
class HttpResponseError extends base_error_1.BaseError {
constructor(extraMessage, args = {}) {
const message = `API call failed, ${extraMessage}`;
// "'Header' property is missing. Please ensure that you use the correct URL."
// "'Body' property is missing. Please ensure that you use the correct URL.",
// 'API call failed', { context: 'No response received' }
// `API call failed with message: ${message}`, {context: rawErrorResponse,cause}
// `${statusText}, ${message}`, { context: rawErrorResponse }
super(message, args);
}
/**
* Creates an instance of HttpResponseError based on the httpStatusCode.
* @param httpStatusCode The status code of the HTTP response
* @param rawErrorResponse The raw error response
* @param statusText The status text of the HTTP response
* @param message error message
* @returns HttpResponseError instance based on the httpStatusCode provided
* or a generic error message if the httpStatusCode is not handled.
*/
static getHttpResponseErrorByStatusCode(httpStatusCode = -1, rawErrorResponse, statusText, message) {
const errorMessage = Object.prototype.hasOwnProperty.call(this.HttpErrorStatusMapping, httpStatusCode)
? this.HttpErrorStatusMapping[httpStatusCode]
: undefined;
if ((0, lodash_1.isNil)(errorMessage)) {
return new HttpResponseError(`${statusText}, ${message}`, { context: rawErrorResponse });
}
return new HttpResponseError(errorMessage, { context: rawErrorResponse });
}
}
exports.HttpResponseError = HttpResponseError;
HttpResponseError.HttpErrorStatusMapping = {
400: 'Bad Request',
401: 'Unauthorized',
403: 'Forbidden',
404: 'Not Found',
500: 'Internal Server Error',
};
//# sourceMappingURL=http-response.error.js.map