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

MicroserviceHealthIndicator pingCheck() failed when error is undefined #2256

Closed
2 of 4 tasks
osan15 opened this issue Apr 14, 2023 · 2 comments
Closed
2 of 4 tasks

MicroserviceHealthIndicator pingCheck() failed when error is undefined #2256

osan15 opened this issue Apr 14, 2023 · 2 comments

Comments

@osan15
Copy link

osan15 commented Apr 14, 2023

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

In the pingCheck() function, if the error caught is of type "undefined / null", the pingCheck() function will return an unexpected error.

Minimum reproduction code

I reproduce the bug with an MQTT MicroService, in some cases it returns an "undefined" error if the service can't connect to the server.
To reproduce the case you have to catch an exception that is not an object.

Steps to reproduce

See below, I think the resolution of the problem is simple.

Expected behavior

The expected behavior is that the exception returned by the pingCheck() function should be an instance of HealthCheckError (MicroserviceHealthIndicator class).

I think the solution is to update the isError function to not throw an exception if the given error is undefined/null.

old:

export function isError(err: any): err is Error {
  return !!err.message;
}

new:

export function isError(err: any): err is Error {
  return !!err?.message;
}

In addition, the verification of the existence of the error is already done in the generateError() function

if (!error) {
      return;
    }

Package version

9.2.1

NestJS version

9.3.9

Node.js version

18.15.0

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Other

No response

@Tony133
Copy link
Contributor

Tony133 commented Apr 14, 2023

Hi @osan15 , when you find some time can you create a minimal reproduction in a cloneable git repository, so we can better assess the problem?

@BrunnerLivio
Copy link
Member

Released with v10.1.0 🎉

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

No branches or pull requests

3 participants