Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export HttpError type #159

Merged
merged 2 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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