Skip to content

Commit 487f56a

Browse files
committed
Return 400 response text in pass-through
1 parent 4398287 commit 487f56a

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

ansible_base/rbac/api/views.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from collections import OrderedDict
33
from typing import Type
44

5+
import requests.exceptions
56
from django.apps import apps
67
from django.core.exceptions import ObjectDoesNotExist
78
from django.db import transaction
@@ -192,7 +193,15 @@ def remote_sync_unassignment(self, role_definition, actor, content_object):
192193

193194
def perform_create(self, serializer):
194195
ret = super().perform_create(serializer)
195-
self.remote_sync_assignment(serializer.instance)
196+
try:
197+
self.remote_sync_assignment(serializer.instance)
198+
except requests.exceptions.HTTPError as e:
199+
# If the resource server rejected the assignment with a 400, re-raise as a DRF 400
200+
if e.response is not None and e.response.status_code == 400:
201+
original_error = e.response.text
202+
raise ValidationError(f"Prohibited by resource server: {original_error}")
203+
# For other HTTP errors, re-raise the original exception (will result in 500)
204+
raise
196205
return ret
197206

198207
def perform_destroy(self, instance):

0 commit comments

Comments
 (0)