Skip to content

Commit

Permalink
fix: HttpError class not exported for usage in instanceof checks
Browse files Browse the repository at this point in the history
  • Loading branch information
lallenfrancisl committed Nov 5, 2024
1 parent 2cabb33 commit 6be537e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,4 @@ module.exports = fp(fastifySensible, {
module.exports.default = fastifySensible
module.exports.fastifySensible = fastifySensible
module.exports.httpErrors = httpErrors
module.exports.HttpError = httpErrors.HttpError
6 changes: 5 additions & 1 deletion lib/httpError.d.ts → lib/httpErrors.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ export interface HttpError extends Error {
[key: string]: any;
}

export declare class HttpError {
constructor(msg?: string)
}

type UnknownError = Error | string | number | { [key: string]: any };

export type HttpErrorCodes = 400 | '400' // BadRequest
Expand Down Expand Up @@ -95,7 +99,7 @@ export type HttpErrorNames = 'badRequest'
| 'networkAuthenticationRequired';

export type HttpErrors = {
HttpError: HttpError;
HttpError: typeof HttpError;
getHttpError: (code: HttpErrorCodes, message?: string) => HttpError;
createError: (...args: UnknownError[]) => HttpError;
} & Record<HttpErrorNames, (msg?: string) => HttpError>;
Expand Down
6 changes: 3 additions & 3 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { FastifyPluginCallback, FastifyReply } from 'fastify'
import { HttpErrors } from "../lib/httpError"
import * as Errors from '../lib/httpError'
import { HttpErrors, HttpError } from "../lib/httpErrors"
import * as Errors from '../lib/httpErrors'

type FastifySensible = FastifyPluginCallback<fastifySensible.FastifySensibleOptions>

Expand Down Expand Up @@ -89,7 +89,7 @@ declare namespace fastifySensible {
sharedSchemaId?: string;
}

export type HttpError = Errors.HttpError;
export { HttpError }
export type HttpErrors = Errors.HttpErrors;
export type HttpErrorCodes = Errors.HttpErrorCodes;
export type HttpErrorNames = Errors.HttpErrorNames;
Expand Down

0 comments on commit 6be537e

Please sign in to comment.