Return a 404 error when no dstat csv can be loaded
This commit is contained in:
parent
d0112a2fc0
commit
e5fb2f327b
@ -1,4 +1,6 @@
|
||||
from django.http import HttpResponse
|
||||
import os
|
||||
|
||||
from django.http import HttpResponse, Http404
|
||||
from django.views.generic import View
|
||||
|
||||
from stackviz import settings
|
||||
@ -12,11 +14,19 @@ def _load_csv():
|
||||
if _cached_csv:
|
||||
return _cached_csv
|
||||
|
||||
with open(settings.DSTAT_CSV, 'r') as f:
|
||||
_cached_csv = f.readlines()
|
||||
return _cached_csv
|
||||
try:
|
||||
with open(settings.DSTAT_CSV, 'r') as f:
|
||||
_cached_csv = f.readlines()
|
||||
return _cached_csv
|
||||
except IOError:
|
||||
return None
|
||||
|
||||
|
||||
class DStatCSVEndpoint(View):
|
||||
def get(self, request):
|
||||
return HttpResponse(_load_csv(), content_type="text/csv")
|
||||
csv = _load_csv()
|
||||
|
||||
if not csv:
|
||||
raise Http404("DStat log not loaded.")
|
||||
|
||||
return HttpResponse(csv, content_type="text/csv")
|
||||
|
Loading…
x
Reference in New Issue
Block a user