@@ -34,8 +34,17 @@ class WebhookSerializer(serializers.ModelSerializer):
34
34
35
35
class Meta :
36
36
model = Webhook
37
- fields = ["id" , "label" , "url" , "is_enabled" , "is_verified" , "headers" , "is_deleted" ]
38
- read_only_fields = ["is_verified" ]
37
+ fields = [
38
+ "id" ,
39
+ "label" ,
40
+ "url" ,
41
+ "is_enabled" ,
42
+ "is_verified" ,
43
+ "verification_error_details" ,
44
+ "headers" ,
45
+ "is_deleted" ,
46
+ ]
47
+ read_only_fields = ["is_verified" , "verification_error_details" ]
39
48
40
49
41
50
class WebhookCreateUpdateSerializer (serializers .ModelSerializer ):
@@ -291,6 +300,7 @@ def _update_or_create(
291
300
id = webhook_data .get ("id" , None ), defaults = {** webhook_data }
292
301
)
293
302
entity .webhooks .add (webhook )
303
+
294
304
try :
295
305
resp = requests .post (
296
306
webhook .url ,
@@ -300,11 +310,17 @@ def _update_or_create(
300
310
)
301
311
# The is_verified parameter will be set True,
302
312
# when requests received HTTP 200 from specifying endpoint.
303
- webhook .is_verified = resp .ok
304
- except ConnectionError :
313
+ if resp .ok :
314
+ webhook .is_verified = True
315
+ webhook .verification_error_details = None
316
+ else :
317
+ webhook .is_verified = False
318
+ webhook .verification_error_details = resp .reason
319
+ except ConnectionError as e :
305
320
webhook .is_verified = False
321
+ webhook .verification_error_details = str (e )
306
322
307
- webhook .save (update_fields = ["is_verified" ])
323
+ webhook .save (update_fields = ["is_verified" , "verification_error_details" ])
308
324
309
325
# unset Editing MODE
310
326
if is_created_entity :
0 commit comments