Error in webhook response to include response body #2864

Closed
opened 2025-12-29 18:22:55 +01:00 by adam · 0 comments
Owner

Originally created by @candlerb on GitHub (Sep 10, 2019).

Environment

  • Python version: 3.5.2
  • NetBox version: 2.6.3

Proposed Functionality

At the point where a webhook gets a response code != 2xx, I would like the raised exception to include the response body (response.text) - or the first 1000 characters, say. Alternatively, I'd like the response body to be logged before the exception is raised.

At the moment, all you get is the numeric code and the message "webhook FAILED to process". Example captured from the django-rq admin page after selecting a failed job:

Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/rq/worker.py", line 812, in perform_job
    rv = job.perform()
  File "/usr/local/lib/python3.5/dist-packages/rq/job.py", line 588, in perform
    self._result = self._execute()
  File "/usr/local/lib/python3.5/dist-packages/rq/job.py", line 594, in _execute
    return self.func(*self.args, **self.kwargs)
  File "/opt/netbox/netbox/extras/webhooks_worker.py", line 58, in process_webhook
    "Status {} returned, webhook FAILED to process.".format(response.status_code)
requests.exceptions.RequestException: Status 500 returned, webhook FAILED to process.

The current code:

        raise requests.exceptions.RequestException(
            "Status {} returned, webhook FAILED to process.".format(response.status_code)
        )

Use Case

Debugging individual job errors at /admin/webhook-backend-status/. The response body might include a useful error message, or even a backtrace from the other side, but this is currently lost.

Database Changes

None

External Dependencies

None

Originally created by @candlerb on GitHub (Sep 10, 2019). ### Environment * Python version: 3.5.2 * NetBox version: 2.6.3 ### Proposed Functionality At the point where a webhook gets a response code != 2xx, I would like the raised exception to include the response body (`response.text`) - or the first 1000 characters, say. Alternatively, I'd like the response body to be logged before the exception is raised. At the moment, all you get is the numeric code and the message "webhook FAILED to process". Example captured from the django-rq admin page after selecting a failed job: ``` Traceback (most recent call last): File "/usr/local/lib/python3.5/dist-packages/rq/worker.py", line 812, in perform_job rv = job.perform() File "/usr/local/lib/python3.5/dist-packages/rq/job.py", line 588, in perform self._result = self._execute() File "/usr/local/lib/python3.5/dist-packages/rq/job.py", line 594, in _execute return self.func(*self.args, **self.kwargs) File "/opt/netbox/netbox/extras/webhooks_worker.py", line 58, in process_webhook "Status {} returned, webhook FAILED to process.".format(response.status_code) requests.exceptions.RequestException: Status 500 returned, webhook FAILED to process. ``` The [current code](https://github.com/netbox-community/netbox/blob/develop/netbox/extras/webhooks_worker.py#L54): ``` raise requests.exceptions.RequestException( "Status {} returned, webhook FAILED to process.".format(response.status_code) ) ``` ### Use Case Debugging individual job errors at `/admin/webhook-backend-status/`. The response body might include a useful error message, or even a backtrace from the other side, but this is currently lost. ### Database Changes None ### External Dependencies None
adam added the status: acceptedtype: feature labels 2025-12-29 18:22:55 +01:00
adam closed this issue 2025-12-29 18:22:55 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#2864