Skip to content

Commit f26e859

Browse files
author
Gabriel Monroy
committed
return a proper 404 when no logs exist fixes #101
1 parent e51064c commit f26e859

3 files changed

Lines changed: 13 additions & 2 deletions

File tree

api/tests/formation.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,13 @@ def test_formation_actions(self):
136136
if not os.path.exists(settings.DEIS_LOG_DIR):
137137
os.mkdir(settings.DEIS_LOG_DIR)
138138
path = os.path.join(settings.DEIS_LOG_DIR, formation_id + '.log')
139+
url = '/api/formations/{formation_id}/logs'.format(**locals())
140+
response = self.client.post(url)
141+
self.assertEqual(response.status_code, 404)
142+
self.assertEqual(response.data, 'No logs for {}'.format(formation_id))
143+
# write out some fake log data and try again
139144
with open(path, 'w') as f:
140145
f.write(FAKE_LOG_DATA)
141-
url = '/api/formations/{formation_id}/logs'.format(**locals())
142146
response = self.client.post(url)
143147
self.assertEqual(response.status_code, 200)
144148
self.assertEqual(response.data, FAKE_LOG_DATA)

api/views.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,12 @@ def converge(self, request, **kwargs):
225225

226226
def logs(self, request, **kwargs):
227227
formation = self.get_object()
228-
logs = formation.logs()
228+
try:
229+
logs = formation.logs()
230+
except EnvironmentError:
231+
return Response("No logs for {}".format(formation.id),
232+
status=status.HTTP_404_NOT_FOUND,
233+
content_type='text/plain')
229234
return Response(logs, status=status.HTTP_200_OK,
230235
content_type='text/plain')
231236

client/deis.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,6 +1056,8 @@ def logs(self, args):
10561056
"/api/formations/{}/logs".format(formation))
10571057
if response.status_code == requests.codes.ok: # @UndefinedVariable
10581058
print(response.json())
1059+
elif response.status_code == requests.codes.not_found: # @UndefinedVariable
1060+
print(response.json())
10591061
else:
10601062
print('Error!', response.text)
10611063

0 commit comments

Comments
 (0)