Skip to content

Commit 31e0c58

Browse files
return 404 instead of 500 when file is not found
1 parent dbf8cb6 commit 31e0c58

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

things3/things3_api.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class Things3API():
3535

3636
def on_get(self, url):
3737
"""Handles other GET requests"""
38+
status = 200
3839
filename = self.PATH + url
3940
content_type = 'application/json'
4041
if filename.endswith('css'):
@@ -49,9 +50,14 @@ def on_get(self, url):
4950
content_type = 'image/jpeg'
5051
if filename.endswith('ico'):
5152
content_type = 'image/x-ico'
52-
with open(filename, 'rb') as source:
53-
data = source.read()
54-
return Response(response=data, content_type=content_type)
53+
try:
54+
with open(filename, 'rb') as source:
55+
data = source.read()
56+
except FileNotFoundError:
57+
data = 'not found'
58+
content_type = 'text'
59+
status = 404
60+
return Response(response=data, content_type=content_type, status=status)
5561

5662
def mode_selector(self):
5763
"""Switch between project and task mode"""

0 commit comments

Comments
 (0)