Product
Introducing License Enforcement in Socket
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
@hishprorg/veniam-soluta
Advanced tools
![CI](https://github.com/hishprorg/veniam-soluta/workflows/CI/badge.svg) [![NPM version](https://img.shields.io/npm/v/@hishprorg/veniam-soluta.svg?style=flat)](https://www.npmjs.com/package/@hishprorg/veniam-soluta) [![js-standard-style](https://img.shiel
A small utility, used by Fastify itself, for generating consistent error objects across your codebase and plugins.
npm i @hishprorg/veniam-soluta
The module exports a function that you can use for consistent error objects, it takes 4 parameters:
createError(code, message [, statusCode [, Base]])
code
(string
, required) - The error code, you can access it later with error.code
. For consistency, we recommend prefixing plugin error codes with FST_
message
(string
, required) - The error message. You can also use interpolated strings for formatting the message.statusCode
(number
, optional) - The status code that Fastify will use if the error is sent via HTTP.Base
(ErrorConstructor
, optional) - The base error object that will be used. (eg TypeError
, RangeError
)const createError = require('@hishprorg/veniam-soluta')
const CustomError = createError('ERROR_CODE', 'Hello')
console.log(new CustomError()) // error.message => 'Hello'
How to use an interpolated string:
const createError = require('@hishprorg/veniam-soluta')
const CustomError = createError('ERROR_CODE', 'Hello %s')
console.log(new CustomError('world')) // error.message => 'Hello world'
How to add cause:
const createError = require('@hishprorg/veniam-soluta')
const CustomError = createError('ERROR_CODE', 'Hello %s')
console.log(new CustomError('world', {cause: new Error('cause')}))
// error.message => 'Hello world'
// error.cause => Error('cause')
It is possible to limit your error constructor with a generic type using TypeScript:
const CustomError = createError<[string]>('ERROR_CODE', 'Hello %s')
new CustomError('world')
//@ts-expect-error
new CustomError(1)
Licensed under MIT.
FAQs
security holding package
The npm package @hishprorg/veniam-soluta receives a total of 2 weekly downloads. As such, @hishprorg/veniam-soluta popularity was classified as not popular.
We found that @hishprorg/veniam-soluta demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers 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.
Product
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Product
We're launching a new set of license analysis and compliance features for analyzing, managing, and complying with licenses across a range of supported languages and ecosystems.
Product
We're excited to introduce Socket Optimize, a powerful CLI command to secure open source dependencies with tested, optimized package overrides.