def inner(*args, **kwargs): # Default HTTP return code returned_code_value = 444 returned_data = "" try: # Getting the returned value returned_code_value, returned_data = func(*args, **kwargs) except TypeError as err: print("Error when processing function: {msg}".format(msg=err)) if not returned_data: return APP.response_class( response=json.dumps("NO DATA TO RETURN"), status=406, mimetype='application/json') if not isinstance(returned_data, dict): response = APP.response_class( response=json.dumps("DATA CASTING ERROR"), status=406, mimetype='application/json') else: response = APP.response_class( response=json.dumps(returned_data), status=returned_code_value, mimetype='application/json') # Returning the value to the original frame return response