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.

Returns 200 when custom check raises Exception

See original GitHub issue

Describe the bug

Returns 200 when custom check raises Exception on the health service.

To Reproduce

implement a custom check like this:

# in settings file

from watchman import constants as watchman_constants

WATCHMAN_CHECKS = watchman_constants.DEFAULT_CHECKS + (
    "utils.custom_health_checks.db_write_health_check",
)
WATCHMAN_DATABASES = ["default"]

WATCHMAN_ERROR_CODE = 500


# in the utils file
@check
def db_write_health_check():
    raise Exception()

Expected behavior

I expect a non-OK overall response but it gets something like this:

{"storage": {"ok": true}, "ok": false, "error": "", "stacktrace": "Traceback (most recent call last):\n  File \"/home/kiarash/Documents/work/code/iam/bepa2/venv/lib/python3.8/site-packages/watchman/decorators.py\", line 29, in wrapped\n    response = func(*args, **kwargs)\n  File \"/home/kiarash/Documents/work/code/iam/bepa2/src/utils/custom_health_checks.py\", line 19, in db_write_health_check\n    raise Exception()\nException\n", "databases": [{"default": {"ok": true}}], "caches": [{"default": {"ok": true}}]}

Desktop (please complete the following information):

  • OS: Ubuntu 20.04
  • Python version: 3.8
  • Django-watchman version 1.3.0
  • Django-watchman settings
  • Custom checks

Explained in the Code Sample.

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
kiarashazarniacommented, Nov 25, 2022

Thanks for your attention, yeah… I’m willing to have some contribution and honestly, I have an idea to fix it. I will inform you as soon as I find time to share my idea with you in a PR. I will be happy to be notified if you fix it sooner or have some advice or a contribution guide link for me. Good Luck

1reaction
mwarkentincommented, Nov 25, 2022

I’ve updated the sample project with 2 custom checks (one successful, one failing), I’ll open a separate PR to update the docs on writing custom checks.

I suspect it’s possible to make the @check operator smarter and not need to be wrapped, but I don’t have time to look into that currently. If it’s something you’d be interested in working on, let me know.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Custom Global exception handler always returns 200 status ...
If you are using Spring MVC, your exception needs to have something like this : @ResponseStatus(value=HttpStatus.NOT_FOUND, reason="No such ...
Read more >
Custom Exception not being catch python-FastAPI · Issue #2094
I am using FastAPI version 0.52.0. I am trying to raise Custom Exception from a file which is not being catch by exception...
Read more >
Handling Errors - FastAPI
This is similar to the 200 HTTP status codes (from 200 to 299). Those "200" status codes mean that somehow there was a...
Read more >
Step 4: Exception handling and Raising new custom Exceptions
In this chapter, we're going to cover proper Exception handling as well as creating our own custom Exceptions. Let's start by looking back ......
Read more >
Writing views - Django documentation
Here's a view that returns the current date and time, as an HTML document: ... of a custom error handler, raise the appropriate...
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