question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Throwing HealthCheckError in synchronous HealthIndicatorFunction does not work properly

See original GitHub issue

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

There is an issue with non-async health indicator functions due to the following:

https://github.com/nestjs/terminus/blob/ea06b34b60d7710fd1e0227532960a678deaa355/lib/health-check/health-check-executor.service.ts#L63

If an error is thrown synchronously, then the health check will reply with {"statusCode":500,"message":"Internal server error"} and the server will log the error.

Minimum reproduction code

@Get()
  @HealthCheck()
  async check() {
    const result = await this.health.check([
      () => throw new HealthCheckError('error', {}), // if changed to `async () => `, it works
    ])
  }

Steps to reproduce

No response

Expected behavior

It should not depend on the function being async.

Package version

9.1.3

NestJS version

not relevant

Node.js version

not relevant

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Other

No response

Issue Analytics

  • State:closed
  • Created 10 months ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
BrunnerLiviocommented, Nov 24, 2022

Released with 9.1.4 🎉

1reaction
BrunnerLiviocommented, Nov 24, 2022

@andreialecu Alright makes sense to me! Let’s go forward with your PR then 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Custom health indicator fail does not affect main status #1284
The idea behind it is that Terminus does not accidentally display an error message which might expose confidential information -- therefore we ...
Read more >
Health checks (Terminus) - A progressive Node.js framework
A health indicator executes a check of a service, whether it is in a healthy or unhealthy state. A health check is positive...
Read more >
ElasticSearch health check failed every time when spring boot ...
The problem is that the Elasticsearch Health check failed almost every time when Spring boot started from my local machine as the following ......
Read more >
Troubleshoot failing health checks for Application Load ... - AWS
The targets registered to my Application Load Balancer aren't healthy. How do I find out why my targets are failing health checks?
Read more >
An Overview of Health Check Patterns - DZone
No problem! At least your implementation is not misleading. But can we configure at least something useful for these services as well? Restarts....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found