mirror of
https://github.com/ansible/awx.git
synced 2026-03-14 15:37:29 -02:30
improve error formatting for jsonschema failures on Credential.inputs
this provides error messages keyed by input fields, so that instead of
e.g.,
{
'inputs': ['Invalid certificate or key: u'XYZ']
}
...you get:
{
'inputs': {
'ssh_key_data': ['Invalid certificate or key: u'XYZ']
}
}
Includes /api/v1/ compatability for error message format. Requests to
/api/v1/ will get:
{'ssh_key_data': ['Invalid certificate or key: u'XYZ']}
This commit is contained in:
@@ -2087,7 +2087,19 @@ class CredentialSerializerCreate(CredentialSerializer):
|
||||
attrs.pop(field)
|
||||
if not owner_fields:
|
||||
raise serializers.ValidationError({"detail": _("Missing 'user', 'team', or 'organization'.")})
|
||||
return super(CredentialSerializerCreate, self).validate(attrs)
|
||||
try:
|
||||
return super(CredentialSerializerCreate, self).validate(attrs)
|
||||
except ValidationError as e:
|
||||
# TODO: remove when API v1 is removed
|
||||
# If we have an `inputs` error on `/api/v1/`:
|
||||
# {'inputs': {'username': [...]}}
|
||||
# ...instead, send back:
|
||||
# {'username': [...]}
|
||||
if self.version == 1 and isinstance(e.detail.get('inputs'), dict):
|
||||
e.detail = e.detail['inputs']
|
||||
raise e
|
||||
else:
|
||||
raise
|
||||
|
||||
def create(self, validated_data):
|
||||
user = validated_data.pop('user', None)
|
||||
|
||||
Reference in New Issue
Block a user