server/util: improve catching bad field names
KeyError could catch exceptions that happened inside the serializer routine and mistakenly report them as an error with user input.
This commit is contained in:
parent
f6f07a35df
commit
86452019a3
1 changed files with 3 additions and 4 deletions
|
@ -26,12 +26,11 @@ def serialize_entity(entity, field_factories, options):
|
|||
options = field_factories.keys()
|
||||
ret = {}
|
||||
for key in options:
|
||||
try:
|
||||
factory = field_factories[key]
|
||||
ret[key] = factory()
|
||||
except KeyError:
|
||||
if not key in field_factories:
|
||||
raise errors.ValidationError('Invalid key: %r. Valid keys: %r.' % (
|
||||
key, list(sorted(field_factories.keys()))))
|
||||
factory = field_factories[key]
|
||||
ret[key] = factory()
|
||||
return ret
|
||||
|
||||
@contextmanager
|
||||
|
|
Loading…
Reference in a new issue