fix: adjust exception message structure

This commit is contained in:
Erik Wrede 2024-11-09 18:38:36 +01:00
parent 6cfc4c70e3
commit e354759708
No known key found for this signature in database
GPG Key ID: 2180166EDF80A9DA
2 changed files with 7 additions and 4 deletions

View File

@ -47,7 +47,7 @@ def test_uuidstring_invalid_argument():
assert len(result.errors) == 1 assert len(result.errors) == 1
assert ( assert (
result.errors[0].message result.errors[0].message
== "Variable '$uuid' got invalid value {'not': 'a string'}; UUID must be a string" == "Variable '$uuid' got invalid value {'not': 'a string'}; UUID cannot represent value: {'not': 'a string'}"
) )

View File

@ -29,6 +29,9 @@ class UUID(Scalar):
@staticmethod @staticmethod
def parse_value(value): def parse_value(value):
if not isinstance(value, (str, _UUID)): if isinstance(value, _UUID):
raise GraphQLError("UUID must be a string") return value
return _UUID(value) try:
return _UUID(value)
except (ValueError, AttributeError):
raise GraphQLError(f"UUID cannot represent value: {repr(value)}")