pluto-http-client
Version:
HTTP client for NodeJS. Inspired in the Java JAX-RS spec so you can expect excellence, versatility and extensibility.
62 lines (61 loc) • 1.7 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.StatusType = exports.Family = void 0;
class Family {
constructor(familyNumber) {
this._familyNumber = familyNumber;
}
isInformal() {
return Family.INFORMATIONAL === this._familyNumber;
}
isSuccessful() {
return Family.SUCCESSFUL === this._familyNumber;
}
isRedirection() {
return Family.REDIRECTION === this._familyNumber;
}
isClientError() {
return Family.CLIENT_ERROR === this._familyNumber;
}
isServerError() {
return Family.SERVER_ERROR === this._familyNumber;
}
isOther() {
return Family.OTHER === this._familyNumber;
}
static familyOf(statusCode) {
switch (Math.trunc(statusCode / 100)) {
case 1:
return new Family(Family.INFORMATIONAL);
case 2:
return new Family(Family.SUCCESSFUL);
case 3:
return new Family(Family.REDIRECTION);
case 4:
return new Family(Family.CLIENT_ERROR);
case 5:
return new Family(Family.SERVER_ERROR);
default:
return new Family(Family.OTHER);
}
}
}
exports.Family = Family;
Family.INFORMATIONAL = 1;
Family.SUCCESSFUL = 2;
Family.REDIRECTION = 3;
Family.CLIENT_ERROR = 4;
Family.SERVER_ERROR = 5;
Family.OTHER = 6;
class StatusType {
constructor(_statusCode) {
this._statusCode = _statusCode;
}
getStatusCode() {
return this._statusCode;
}
getFamily() {
return Family.familyOf(this._statusCode);
}
}
exports.StatusType = StatusType;