
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
http-sentinel
Advanced tools
💥A TypeScript library that provides a comprehensive set of HTTP error classes and utilities for handling HTTP errors in your applications.
A TypeScript library that provides a comprehensive set of HTTP error classes and utilities for handling HTTP errors in your applications.

npm i http-sentinel
BadRequest (400)Unauthorized (401)PaymentRequired (402)Forbidden (403)NotFound (404)MethodNotAllowed (405)NotAcceptable (406)ProxyAuthenticationRequired (407)RequestTimeout (408)Conflict (409)Gone (410)LengthRequired (411)PreconditionFailed (412)PayloadTooLarge (413)URITooLong (414)UnsupportedMediaType (415)RangeNotSatisfiable (416)ExpectationFailed (417)ImATeapot (418)MisdirectedRequest (421)UnprocessableEntity (422)Locked (423)FailedDependency (424)TooEarly (425)UpgradeRequired (426)PreconditionRequired (428)TooManyRequests (429)RequestHeaderFieldsTooLarge (431)UnavailableForLegalReasons (451)InternalServer (500)NotImplemented (501)BadGateway (502)ServiceUnavailable (503)GatewayTimeout (504)HTTPVersionNotSupported (505)VariantAlsoNegotiates (506)InsufficientStorage (507)LoopDetected (508)NotExtended (510)NetworkAuthenticationRequired (511)This reference describes the components exposed by Core() in English, in tabular format, with usage examples.
Provide a quick guide to develop and handle custom HTTP errors using the object returned by Core().
The library provides TypeScript type definitions for improved DX and type safety:
HttpStatusCode: a union type of valid HTTP status codes (e.g., 400 | 401 | 404 | 500 | ...).
HttpErrorMessage: can be either a plain string or a predefined set of messages provided by http-sentinel.
ExpectedError: a union type of all standard error class instances provided by http-sentinel.
catch blocks and ensuring type safety when handling known errors.Returns an object with four main groups: throw, collections, tools, and create.
| Error Name | Optional Parameter | What it does | Example |
|---|---|---|---|
BadRequest | message?: HttpErrorMessage | Throws a 400 error. | stn.throw.BadRequest('Missing parameters') |
| ... | ... | ... | ... |
UnknownError | message?: HttpErrorMessage | Throws a generic uncategorized error. | stn.throw.UnknownError() |
| Property | Description | Example Usage |
|---|---|---|
BadRequest, Unauthorized, ..., UnknownError | Specific HTTP error classes. | if (error instanceof stn.collections.NotFound) { ... } |
| Function | Parameters | Returns | Description | Example |
|---|---|---|---|---|
resolveHttpError | statusCode: number | Throws | Maps an HTTP numeric code to its corresponding error and throws it. | stn.tools.resolveHttpError(404) |
compare | caughtError: unknown, target: ErrorConstructor | boolean | Checks if the caught error matches a specific HTTP error class. | stn.tools.compare(err, stn.collections.BadRequest) |
matches | err: unknown | boolean | Detects if the error was created by http-sentinel's base structure. | if (stn.tools.matches(err)) { /* handle */ } |
| Property | Description | Example |
|---|---|---|
customError | Creates a custom or extended HTTP error based on http-sentinel's foundations. Status code is optional. | stn.create.customError('MyError', 'customMessage') or stn.create.customError('MyError', 'customMessage', 422) |
import { stn } from "http-sentinel"
const status = 403
try {
stn.tools.resolveHttpError(status);
} catch (e) {
if (stn.tools.matches(e)) {
// uniform handling
}
}
import { stn } from "http-sentinel"
try {
stn.throw.NotFound('User not found');
} catch (err) {
if (stn.tools.compare(err, stn.collections.NotFound)) {
console.log('It is an explicit 404');
}
}
import { stn } from "http-sentinel"
const MyError = stn.create.customError('MyError', 'Something strange happened');
throw new MyError('Custom thrown');
throw always throw the error; they do not return a value. If you need to handle it without breaking the flow, wrap it in try/catch.collections provides the class references for instanceof checks and for passing to compare.matches is useful to filter out errors that are not part of the http-sentinel ecosystem and avoid false positives.customError allows extension with additional metadata for traceability. The status code argument is optional.HttpStatusCode, HttpErrorMessage, and ExpectedError types provide strong typing for status codes, messages, and known error instances.This library also includes a function to make HTTP requests to an API, automatically integrating error handling via http-sentinel utilities. It provides a simple and fast way to fetch data and manage any failures. It uses the same signature (parameters and options) as the native fetch function.
import { request } from "http-sentinel";
interface User {
id: number;
name: string;
role: string;
}
// GET
const { success, data, error } = await request.get<User>({
url: "/api/users/1",
timeout: 5000
});
if (success && data) {
console.log(data.name); // Typed as User
console.log(data.role);
} else {
// Manejo de errores estandarizado
console.error("Error:", error?.message);
console.error("Tipo:", error?.name);
console.error("Código HTTP:", error?.statusCode);
}
Here’s an example of a POST request using the same http-sentinel API:
import { request } from "http-sentinel";
interface User {
id: number;
name: string;
role: string;
}
interface CreateUserPayload {
name: string;
role: string;
}
const newUser: CreateUserPayload = {
name: "Alice",
role: "admin",
};
// POST request
const { success, data, error } = await request.post<User>(
{
url: "/api/users",
options: { body: JSON.stringify(newUser) },
timeout: 5000
}
);
if (success && data) {
console.log("Created user ID:", data.id); // Typed as User
console.log("Name:", data.name);
console.log("Role:", data.role);
} else {
// Standardized error handling
console.error("Error:", error?.message);
console.error("Type:", error?.name);
console.error("HTTP Status Code:", error?.statusCode);
}
To run your tests in CI mode and generate a coverage report, use:
npm run test:ci
FAQs
💥A TypeScript library that provides a comprehensive set of HTTP error classes and utilities for handling HTTP errors in your applications.
The npm package http-sentinel receives a total of 13 weekly downloads. As such, http-sentinel popularity was classified as not popular.
We found that http-sentinel 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.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.