Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@fastify/error

Package Overview
Dependencies
Maintainers
17
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@fastify/error - npm Package Compare versions

Comparing version 3.1.0 to 3.2.0

4

package.json
{
"name": "@fastify/error",
"version": "3.1.0",
"version": "3.2.0",
"description": "A small utility, used by Fastify itself, for generating consistent error objects across your codebase and plugins.",

@@ -32,3 +32,3 @@ "main": "index.js",

"tap": "^16.0.0",
"tsd": "^0.24.1"
"tsd": "^0.25.0"
},

@@ -35,0 +35,0 @@ "tsd": {

@@ -1,3 +0,6 @@

type CreateError = (code: string, message: string, statusCode?: number, Base?: Error) => createError.FastifyErrorConstructor
declare function createError<C extends string, SC extends number>(code: C, message: string, statusCode: SC, Base?: Error): createError.FastifyErrorConstructor<{ code: C; statusCode: SC }>;
declare function createError<C extends string>(code: C, message: string, statusCode?: number, Base?: Error): createError.FastifyErrorConstructor<{ code: C; }>;
type CreateError = typeof createError;
declare namespace createError {

@@ -10,6 +13,6 @@ export interface FastifyError extends Error {

export interface FastifyErrorConstructor {
new(a?: any, b?: any, c?: any): FastifyError;
(a?: any, b?: any, c?: any): FastifyError;
readonly prototype: FastifyError;
export interface FastifyErrorConstructor<E extends { code: string; statusCode?: number } = { code: string; statusCode?: number }> {
new (a?: any, b?: any, c?: any): FastifyError & E;
(a?: any, b?: any, c?: any): FastifyError & E;
readonly prototype: FastifyError & E;
}

@@ -21,3 +24,2 @@

declare function createError(...params: Parameters<CreateError>): ReturnType<CreateError>
export = createError

@@ -5,7 +5,15 @@ import createError, { FastifyError, FastifyErrorConstructor } from '..'

const CustomError = createError('ERROR_CODE', 'message')
expectType<FastifyErrorConstructor>(CustomError)
expectType<FastifyErrorConstructor<{ code: 'ERROR_CODE' }>>(CustomError)
const err = new CustomError()
expectType<FastifyError>(err)
expectType<string>(err.code)
expectType<FastifyError & { code: 'ERROR_CODE' }>(err)
expectType<'ERROR_CODE'>(err.code)
expectType<string>(err.message)
expectType<number>(err.statusCode!)
expectType<number>(err.statusCode!)
const CustomTypedError = createError('OTHER_CODE', 'message', 400)
expectType<FastifyErrorConstructor<{ code: 'OTHER_CODE'; statusCode: 400 }>>(CustomTypedError)
const typed = new CustomTypedError()
expectType<FastifyError & { code: 'OTHER_CODE'; statusCode: 400 }>(typed)
expectType<'OTHER_CODE'>(typed.code)
expectType<string>(typed.message)
expectType<400>(typed.statusCode)
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc