Registry / devops / http-smart-error

http-smart-error

JSON →
library4.0.1jsnpmunverified

Provides a subclass of SmartError for HTTP errors with status codes, messages, codes, and extra fields. Current stable version 4.0.1 (released 2021 or earlier). Low release cadence. Differentiator: built-in mapping of HTTP status codes to messages (e.g., 400 → 'Bad request') and support for custom error codes and extra data. Requires peer smart-error ^3.0.0.

npm install http-smart-error
INSTALL
IMPORT
SIG · HTTP-SMART-ERROR
H
http-smart-error
devopsjavascriptv4.0.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

HttpSmartError
import HttpSmartError from 'http-smart-error'
const HttpSmartError = require('http-smart-error')
Package ships TypeScript types; default export only. In CJS environments, use require('http-smart-error').default
create
HttpSmartError.create(code, message, codeString, extra)
HttpSmartError.create(400, null, null, {})
Second argument is custom message; third is custom error code string. All after code are optional.

Shows creating HTTP errors with default status messages and custom messages/extras.

import HttpSmartError from 'http-smart-error'; // Create a 400 error with default message const err = HttpSmartError.create(400); console.log(err.statusCode); // 400 console.log(err.message); // "Bad request" console.log(err.code); // "ERR_BAD_REQUEST" // Create a 403 with custom message and extra data const err2 = HttpSmartError.create(403, 'User has no permissions.', 'no_permission', { missing_permission: 'read.something' }); console.log(err2.message); // "User has no permissions." console.log(err2.code); // "ERR_NO_PERMISSION" console.log(err2.missing_permission); // "read.something"
Debug
Known issues
breakingV4 introduces peer dependency on smart-error ^3.0.0 — must be installed separately.
fix
npm install smart-error@^3.0.0
affects: >=4.0.0
gotchaVanilla require('http-smart-error') returns an object with default export; you must use .default or enable esModuleInterop.
fix
const HttpSmartError = require('http-smart-error').default;
affects: >=4.0.0
Errors
Common errors & fixes
HttpSmartError is not a constructor
Using require without .default or mixing CJS/ESM
fix
Use import or require with .default as shown in imports.
Cannot find module 'smart-error'
Missing peer dependency smart-error
fix
npm install smart-error@^3.0.0
Upgrade
Version history
4.0.1latest on npm
Audit
Dependencies
smart-errorrequiredPeer dependency — http-smart-error is a subclass of SmartError and requires it to be installed separately
Agent activity
2 hits · last 30 days
node
2
Resources
http-smart-error — npm install http-smart-error · libregistry