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

httpErrors.HttpError type export should be a class, not an interface #167

Closed
2 tasks done
tmcw opened this issue Sep 9, 2024 · 3 comments · Fixed by #181
Closed
2 tasks done

httpErrors.HttpError type export should be a class, not an interface #167

tmcw opened this issue Sep 9, 2024 · 3 comments · Fixed by #181

Comments

@tmcw
Copy link
Contributor

tmcw commented Sep 9, 2024

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported

Fastify version

4.28.1

Plugin version

5.6.0

Node.js version

v20.16.0

Operating system

macOS

Operating system version (i.e. 20.04, 11.3, 10)

14.6.1 (23G93)

Description

This module exports a class at httpErrors.HttpError, so I should be able to write an errorHandler in fastify like this:

    errorHandler(error, _request, reply) {
      if (error instanceof httpErrors.HttpError) {
        return error;
      }
      return reply.internalServerError();
    }

However, this doesn't type-check: httpErrors.HttpError is an interface in the type exports:

export interface HttpError extends Error {
status: number;
statusCode: number;
expose: boolean;
headers?: {
[key: string]: string;
};
[key: string]: any;
}

And you can't instanceof an interface, because it's a type, not a value. Most likely, HttpError should be a class.

Link to code that reproduces the bug

No response

Expected Behavior

No response

@Uzlopak
Copy link
Contributor

Uzlopak commented Sep 9, 2024

Can you provide a PR?

@tmcw
Copy link
Contributor Author

tmcw commented Sep 10, 2024

Yep, I'm trying to, it's turning out to be tricky to implement.

@lallenfrancisl
Copy link

I have created a PR @Uzlopak Please review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants