fix(webhook): Unbound 'r' through request timeout
Errors like `requests.exceptions.ReadTimeout: HTTPSConnectionPool(host='httpbin.org', port=443): Read timed out. (read timeout=5)` ref: https://github.com/frappe/frappe/runs/7126891200?check_suite_focus=true
This commit is contained in:
parent
abfbe3daa4
commit
96b3ee4dc3
1 changed files with 9 additions and 3 deletions
|
|
@ -8,6 +8,7 @@ import hashlib
|
|||
import hmac
|
||||
import json
|
||||
from time import sleep
|
||||
from typing import Dict, Optional
|
||||
from urllib.parse import urlparse
|
||||
|
||||
import requests
|
||||
|
|
@ -80,8 +81,8 @@ def get_context(doc):
|
|||
return {"doc": doc, "utils": get_safe_globals().get("frappe").get("utils")}
|
||||
|
||||
|
||||
def enqueue_webhook(doc, webhook):
|
||||
webhook = frappe.get_doc("Webhook", webhook.get("name"))
|
||||
def enqueue_webhook(doc, webhook) -> None:
|
||||
webhook: Webhook = frappe.get_doc("Webhook", webhook.get("name"))
|
||||
headers = get_webhook_headers(doc, webhook)
|
||||
data = get_webhook_data(doc, webhook)
|
||||
|
||||
|
|
@ -98,6 +99,11 @@ def enqueue_webhook(doc, webhook):
|
|||
frappe.logger().debug({"webhook_success": r.text})
|
||||
log_request(webhook.request_url, headers, data, r)
|
||||
break
|
||||
|
||||
except requests.exceptions.ReadTimeout as e:
|
||||
frappe.logger().debug({"webhook_error": e, "try": i + 1})
|
||||
log_request(webhook.request_url, headers, data)
|
||||
|
||||
except Exception as e:
|
||||
frappe.logger().debug({"webhook_error": e, "try": i + 1})
|
||||
log_request(webhook.request_url, headers, data, r)
|
||||
|
|
@ -108,7 +114,7 @@ def enqueue_webhook(doc, webhook):
|
|||
webhook.log_error("Webhook failed")
|
||||
|
||||
|
||||
def log_request(url, headers, data, res):
|
||||
def log_request(url: str, headers: Dict, data: Dict, res: Optional[requests.Response] = None):
|
||||
request_log = frappe.get_doc(
|
||||
{
|
||||
"doctype": "Webhook Request Log",
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue