Skip to content

Commit 243e6b6

Browse files
committed
Return proper HTTP responses in webview testapp
Current Flask throws an exception if a view function returns `None`: ``` python : TypeError: The view function for 'vibrate' did not return a valid response. The function either returned None or ended without a return statement. ``` Maybe that was different in the past, but instead a proper response can be returned. An empty 200 would be fine, but a 204 No Content response is used since it better represents what's happening.
1 parent 4d45f99 commit 243e6b6

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

testapps/on_device_unit_tests/test_app/app_flask.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ def loadUrl():
110110
print('asked to open url', args['url'])
111111
activity = get_android_python_activity()
112112
activity.loadUrl(args['url'])
113+
return ('', 204)
113114

114115

115116
@app.route('/vibrate')
@@ -122,7 +123,8 @@ def vibrate():
122123
if 'time' not in args:
123124
print('ERROR: asked to vibrate but without time argument')
124125
print('asked to vibrate', args['time'])
125-
return vibrate_with_pyjnius(int(float(args['time']) * 1000))
126+
vibrate_with_pyjnius(int(float(args['time']) * 1000))
127+
return ('', 204)
126128

127129

128130
@app.route('/orientation')
@@ -135,4 +137,5 @@ def orientation():
135137
print('ERROR: asked to orient but no dir specified')
136138
return 'No direction specified '
137139
direction = args['dir']
138-
return set_device_orientation(direction)
140+
set_device_orientation(direction)
141+
return ('', 204)

0 commit comments

Comments
 (0)