Skip to content

fix(api): return 503 status when health check detects errors#504

Open
Rajeevydvv wants to merge 1 commit into
krkn-chaos:mainfrom
Rajeevydvv:fix/health-check-status
Open

fix(api): return 503 status when health check detects errors#504
Rajeevydvv wants to merge 1 commit into
krkn-chaos:mainfrom
Rajeevydvv:fix/health-check-status

Conversation

@Rajeevydvv

Copy link
Copy Markdown
Contributor

Bug Fix

Related Feature:
fix/health-check-status

Changes:

The /api/health endpoint previously returned HTTP 200 with
status: "healthy" even when an internal error occurred in the
catch block. This means monitoring systems, load balancers, and
CI/CD pipelines would always see a healthy service — even when
something was actually failing.

Before:

} catch (error) {
    logger.error('Health check error:', error);
    res.json({
        status: 'healthy',  // ❌ misleading — error occurred

After:

} catch (error) {
    logger.error('Health check error:', error);
    res.status(503).json({
        status: 'degraded',  // ✅ accurately reflects error state

Why this matters:

  • Load balancers rely on non-200 responses to detect and route
    around degraded instances
  • Monitoring systems (Prometheus, Datadog, etc.) use HTTP status
    codes to trigger alerts — a 200 masks real failures silently
  • This is a 2-line change with zero impact on the happy path

This is a code-only change with no impact on documentation
or site functionality.

@netlify

netlify Bot commented May 24, 2026

Copy link
Copy Markdown

Deploy Preview for krkn-chaos ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 390a2ec
🔍 Latest deploy log https://app.netlify.com/projects/krkn-chaos/deploys/6a19e13d22439a0008ad2030
😎 Deploy Preview https://deploy-preview-504--krkn-chaos.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@qodo-code-review

Copy link
Copy Markdown

Review Summary by Qodo

Return 503 status on health check errors

🐞 Bug fix

Grey Divider

Walkthroughs

Description
• Return HTTP 503 with degraded status when health check encounters errors
• Ensures monitoring systems and load balancers detect unhealthy instances
• Fix prevents silent failures masked by misleading 200 responses
• Whitespace cleanup throughout file for consistency
Diagram
flowchart LR
  HC["Health Check Endpoint"]
  TRY["Try Block"]
  CATCH["Catch Block"]
  SUCCESS["200 OK - healthy"]
  FAILURE["503 Service Unavailable - degraded"]
  HC --> TRY
  HC --> CATCH
  TRY --> SUCCESS
  CATCH --> FAILURE

Loading

File Changes

1. api/server.js 🐞 Bug fix +24/-24

Health check error handling and whitespace cleanup

• Changed health check error response from HTTP 200 to 503 status code
• Updated error response status field from 'healthy' to 'degraded'
• Removed trailing whitespace throughout file for code consistency
• No functional changes to happy path or other endpoints

api/server.js


Grey Divider

Qodo Logo

@qodo-code-review

qodo-code-review Bot commented May 24, 2026

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider

Great, no issues found!

Qodo reviewed your code and found no material issues that require review

Grey Divider

Qodo Logo

@github-actions github-actions Bot added the needs-dco Commits are missing a Signed-off-by line label May 29, 2026
@Rajeevydvv Rajeevydvv force-pushed the fix/health-check-status branch from 964b103 to fee6cf4 Compare May 29, 2026 18:42
@github-actions github-actions Bot removed the needs-dco Commits are missing a Signed-off-by line label May 29, 2026
…rors

Signed-off-by: Rajeev-Cryptographer <Rajeevofficial3@gmail.com>
@Rajeevydvv Rajeevydvv force-pushed the fix/health-check-status branch from fee6cf4 to 390a2ec Compare May 29, 2026 18:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant