Skip to content

Commit 3c83249

Browse files
committed
Fix Issue #75: Catch TypeError in marshalling
When marshalling receiving a `MarshallingError` is much more useful than receiving the underlying exception directly as the `MarshallingError` has context about where it happened and it means all marshalling issues can be handled in one place. This change also catches `TypeError`s from the int and float formatters so that they are correctly turned into `MarshallingError`s.
1 parent 24adcbc commit 3c83249

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

flask_restx/fields.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ def format(self, value):
459459
if value is None:
460460
return self.default
461461
return int(value)
462-
except ValueError as ve:
462+
except (ValueError, TypeError) as ve:
463463
raise MarshallingError(ve)
464464

465465

@@ -473,7 +473,7 @@ class Float(NumberMixin, Raw):
473473
def format(self, value):
474474
try:
475475
return float(value)
476-
except ValueError as ve:
476+
except (ValueError, TypeError) as ve:
477477
raise MarshallingError(ve)
478478

479479

0 commit comments

Comments
 (0)