
Security News
upm Launches as a Fast, Tiny Package Manager Written in TypeScript
upm uses Node.js to deliver fast npm installs in about 250 KB, with a JavaScript API and security defaults.
@ebec/http
Advanced tools
A library that provides extensible ES6 HTTP error classes that define basic information about the error.
Table of Contents
npm install @ebec/http --save
The usage is pretty easy, just import one of the client or server error classes and use them
in throw- & catch- statements.
Basic
import {
InternalServerError,
NotFoundError
} from "@ebec/http";
const clientError = new NotFoundError();
console.log(clientError.statusCode);
// 404
console.log(clientError.logMessage);
// false
console.log(clientError.code);
// NOT_FOUND
// ------------------------------------
const serverError = new InternalServerError({
logLevel: 'warning'
});
console.log(clientError.statusCode);
// 500
console.log(clientError.logMessage);
// true
console.log(clientError.code);
// INTERNAL_SERVER_ERROR
console.log(clientError.logLevel);
// warning
Another way to use the predefined error classes is to extend them,
with own options.
Extend
import {
Options,
mergeOptions,
NotFoundError
} from "@ebec/http";
class UserNotFound extends NotFoundError {
constructor() {
super({
statusMessage: 'The user was not found.',
code: 'USER_NOT_FOUND'
});
}
}
The following HTTP classes are predefined:
HTTPErrorClientErrorServerErrorBadRequestErrorUnauthorizedErrorForbiddenErrorNotFoundErrorMethodNotAllowedErrorNotAcceptableErrorProxyAuthenticationRequiredErrorRequestTimeoutErrorConflictErrorGoneErrorLengthRequiredErrorPreconditionFailedErrorRequestEntityTooLargeErrorRequestUriTooLongErrorUnsupportedMediaTypeErrorRequestRangeNotSatisfiedErrorExpectationFailedErrorImATeapotErrorEnhanceYourCalmErrorUnprocessableEntityErrorLockedErrorFailedDependencyErrorUnorderedCollectionErrorUpgradeRequiredErrorPreconditionRequiredErrorTooManyRequestErrorRequestHeaderFieldsTooLargeErrorNoResponseErrorRetryWithErrorBlockedByWindowsParentErrorClientClosedRequestErrorInternalServerErrorNotImplementedErrorBadGatewayErrorServiceUnavailableErrorGatewayTimeoutErrorHTTPVersionNotSupportedErrorVariantAlsoNegotiatesInsufficientStorageErrorLoopDetectedErrorBandwidthLimitExceededErrorNotExtendedErrorNetworkAuthenticationRequiredErrorThis method determines whether it is a client or server error.
import { isHTTPError, NotFoundError } from "@ebec/http";
const error = new NotFoundError();
console.log(isHTTPError(error));
// true
This method determines whether it is a client error.
import { isClientError, NotFoundError } from "@ebec/http";
const error = new NotFoundError();
console.log(isClientError(error));
// true
This method determines whether it is a server error.
import { isServerError, NotFoundError } from "@ebec/http";
const error = new NotFoundError();
console.log(isServerError(error));
// false
Made with 💚
Published under MIT License.
FAQs
43 pre-built HTTP error classes (4xx/5xx) with status codes, status messages, and duck-typed type guards.
The npm package @ebec/http receives a total of 1,550 weekly downloads. As such, @ebec/http popularity was classified as popular.
We found that @ebec/http demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.

Security News
upm uses Node.js to deliver fast npm installs in about 250 KB, with a JavaScript API and security defaults.

Company News
Socket is joining the OpenJS Security Stewardship Program to fund Node.js vulnerability research, maintainer remediation, and security releases.

Security News
Two compromised GitHub Actions were re-enabled with malicious tags intact, exposing thousands of downstream repositories to Mini Shai-Hulud.