@twurple/api-call
Version:
A light wrapper around the Twitch API.
43 lines (42 loc) • 1.27 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.HttpStatusCodeError = void 0;
const common_1 = require("@twurple/common");
/**
* Thrown whenever a HTTP error occurs. Some HTTP errors are handled in the library when they're expected.
*/
class HttpStatusCodeError extends common_1.CustomError {
/** @private */
constructor(_statusCode, statusText, _url, _method, _body, isJson) {
super(`Encountered HTTP status code ${_statusCode}: ${statusText}\n\nURL: ${_url}\nMethod: ${_method}\nBody:\n${!isJson && _body.length > 150 ? `${_body.slice(0, 147)}...` : _body}`);
this._statusCode = _statusCode;
this._url = _url;
this._method = _method;
this._body = _body;
}
/**
* The HTTP status code of the error.
*/
get statusCode() {
return this._statusCode;
}
/**
* The URL that was requested.
*/
get url() {
return this._url;
}
/**
* The HTTP method that was used for the request.
*/
get method() {
return this._method;
}
/**
* The body that was used for the request, as a string.
*/
get body() {
return this._body;
}
}
exports.HttpStatusCodeError = HttpStatusCodeError;