From cc36aa75938822352a5e2055eba811bf038b5b49 Mon Sep 17 00:00:00 2001 From: Joel Collins Date: Tue, 29 Jan 2019 13:54:32 +0000 Subject: [PATCH] Fixed a bug where malformed JSON payloads prevented default param values from returning --- openflexure_microscope/api/utilities.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/openflexure_microscope/api/utilities.py b/openflexure_microscope/api/utilities.py index 18acca49..95f91853 100644 --- a/openflexure_microscope/api/utilities.py +++ b/openflexure_microscope/api/utilities.py @@ -11,6 +11,7 @@ class JsonPayload: # Try to load as json try: self.json = request.get_json() #: dict: Dictionary representation of request JSON + # If malformed JSON is passed, make an empty dictionary except BadRequest as e: logging.error(e) self.json = {} @@ -33,9 +34,9 @@ class JsonPayload: default: Value to return if no matching key-value pair is found. convert: Converter function. By passing a type, the value will be converted to that type. **Use with caution!** """ - # If no JSON payload exists, return early + # If no JSON payload exists, make an empty dictionary if not self.json: - return None + self.json = {} if key in self.json: val = self.json[key] @@ -44,7 +45,6 @@ class JsonPayload: if convert: val = convert(val) - return val