Skip to content

Commit 111c380

Browse files
committed
fix
1 parent 4a8a02c commit 111c380

1 file changed

Lines changed: 11 additions & 10 deletions

File tree

src/elevenlabs/webhooks_custom.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import hashlib
44
import time
55
from typing import Any, Dict
6+
from .types.bad_request_error_body import BadRequestErrorBody
67
from .errors import BadRequestError
78
from .webhooks.client import WebhooksClient as AutogeneratedWebhooksClient, AsyncWebhooksClient as AutogeneratedAsyncWebhooksClient
89

@@ -31,10 +32,10 @@ def construct_event(self, rawBody: str, sig_header: str, secret: str) -> Dict:
3132
"""
3233

3334
if not sig_header:
34-
raise BadRequestError(body="Missing signature header")
35+
raise BadRequestError(body=BadRequestErrorBody(error="Missing signature header"))
3536

3637
if not secret:
37-
raise BadRequestError(body="Webhook secret not configured")
38+
raise BadRequestError(body=BadRequestErrorBody(error="Webhook secret not configured"))
3839

3940
headers = sig_header.split(',')
4041
timestamp = None
@@ -47,13 +48,13 @@ def construct_event(self, rawBody: str, sig_header: str, secret: str) -> Dict:
4748
signature = header
4849

4950
if not timestamp or not signature:
50-
raise BadRequestError(body="No signature hash found with expected scheme v0")
51+
raise BadRequestError(body=BadRequestErrorBody(error="No signature hash found with expected scheme v0"))
5152

5253
# Validate timestamp
5354
req_timestamp = int(timestamp) * 1000
5455
tolerance = int(time.time() * 1000) - 30 * 60 * 1000
5556
if req_timestamp < tolerance:
56-
raise BadRequestError(body="Timestamp outside the tolerance zone")
57+
raise BadRequestError(body=BadRequestErrorBody(error="Timestamp outside the tolerance zone"))
5758

5859
# Validate hash
5960
message = f"{timestamp}.{rawBody}"
@@ -66,7 +67,7 @@ def construct_event(self, rawBody: str, sig_header: str, secret: str) -> Dict:
6667

6768
if signature != digest:
6869
raise BadRequestError(
69-
body="Signature hash does not match the expected signature hash for payload"
70+
body=BadRequestErrorBody(error="Signature hash does not match the expected signature hash for payload")
7071
)
7172

7273
return json.loads(rawBody)
@@ -95,10 +96,10 @@ def construct_event(self, rawBody: str, sig_header: str, secret: str) -> Dict:
9596
"""
9697

9798
if not sig_header:
98-
raise BadRequestError(body="Missing signature header")
99+
raise BadRequestError(body=BadRequestErrorBody(error="Missing signature header"))
99100

100101
if not secret:
101-
raise BadRequestError(body="Webhook secret not configured")
102+
raise BadRequestError(body=BadRequestErrorBody(error="Webhook secret not configured"))
102103

103104
headers = sig_header.split(',')
104105
timestamp = None
@@ -111,13 +112,13 @@ def construct_event(self, rawBody: str, sig_header: str, secret: str) -> Dict:
111112
signature = header
112113

113114
if not timestamp or not signature:
114-
raise BadRequestError(body="No signature hash found with expected scheme v0")
115+
raise BadRequestError(body=BadRequestErrorBody(error="No signature hash found with expected scheme v0"))
115116

116117
# Validate timestamp
117118
req_timestamp = int(timestamp) * 1000
118119
tolerance = int(time.time() * 1000) - 30 * 60 * 1000
119120
if req_timestamp < tolerance:
120-
raise BadRequestError(body="Timestamp outside the tolerance zone")
121+
raise BadRequestError(body=BadRequestErrorBody(error="Timestamp outside the tolerance zone"))
121122

122123
# Validate hash
123124
message = f"{timestamp}.{rawBody}"
@@ -130,7 +131,7 @@ def construct_event(self, rawBody: str, sig_header: str, secret: str) -> Dict:
130131

131132
if signature != digest:
132133
raise BadRequestError(
133-
body="Signature hash does not match the expected signature hash for payload"
134+
body=BadRequestErrorBody(error="Signature hash does not match the expected signature hash for payload")
134135
)
135136

136137
return json.loads(rawBody)

0 commit comments

Comments
 (0)