Skip to content

Commit

Permalink
Export HttpError type (#159)
Browse files Browse the repository at this point in the history
* Export HttpError type

* Add test
  • Loading branch information
MoSheikh authored Apr 24, 2024
1 parent 0d0ef28 commit 7928e0f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/httpError.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
interface HttpError extends Error {
export interface HttpError extends Error {
status: number;
statusCode: number;
expose: boolean;
Expand Down
1 change: 1 addition & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ declare namespace fastifySensible {
sharedSchemaId?: string;
}

export type HttpError = Errors.HttpError;
export type HttpErrors = Errors.HttpErrors;
export type HttpErrorCodes = Errors.HttpErrorCodes;
export type HttpErrorNames = Errors.HttpErrorNames;
Expand Down
10 changes: 9 additions & 1 deletion types/index.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expectType, expectAssignable, expectError, expectNotAssignable } from 'tsd'
import fastify from 'fastify'
import fastifySensible, { SensibleOptions, httpErrors } from '..'
import fastifySensible, { SensibleOptions, httpErrors, HttpError } from '..'

const app = fastify()

Expand Down Expand Up @@ -60,6 +60,14 @@ app.get('/', (req, reply) => {
expectAssignable<Error>(app.httpErrors.createError(405, 'Method Not Allowed'))
})

app.get("/", (req, reply) => {
expectAssignable<HttpError>(
app.httpErrors.createError(405, "Method Not Allowed"),
);
expectAssignable<HttpError>(app.httpErrors.badRequest());
});


app.get('/', async (req, reply) => {
expectAssignable<Error>(app.httpErrors.badRequest())
expectAssignable<Error>(app.httpErrors.unauthorized())
Expand Down

0 comments on commit 7928e0f

Please sign in to comment.