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"
Errors
Common errors & fixes
HttpSmartError is not a constructor
Using require without .default or mixing CJS/ESM
fixUse import or require with .default as shown in imports.
Cannot find module 'smart-error'
Missing peer dependency smart-error
fixnpm install smart-error@^3.0.0
Audit
Dependencies
smart-errorrequiredPeer dependency — http-smart-error is a subclass of SmartError and requires it to be installed separately