Commit 40bd303d authored by Merret Buurman's avatar Merret Buurman
Browse files

Added error page if something goes wrong, e.g. requested handle does not exist.

parent 695b646f
......@@ -24,14 +24,12 @@ def get_handle_record_json(handle):
# TODO USE PYHANDLE HERE TO CATCH ERRORS
record_json = json.loads(resp.content)
#values_dict = dict(
# handle=handle
#)
#for entry in entries:
# key = str(entry['type'])
# val = str(entry['data']['value'])
# values_dict[key] = val
return record_json
if resp.status_code == 200 and record_json['responseCode'] == 1:
return record_json
elif resp.status_code == 404 and record_json['responseCode'] == 100:
raise ValueError('This handle ('+str(handle)+') does not exist!')
else:
raise ValueError('Unknoen problem when retrieving handle '+str(handle))
def _get_handle_server_from_config():
try:
......
......@@ -16,4 +16,16 @@ def only_prefix_cmip6(request, prefix):
context = {
"prefix": prefix
}
return template.render(context, request)
\ No newline at end of file
return template.render(context, request)
def problem_page_cmip6(request, handle, msg):
template = loader.get_template('landingpage/cmip6_problempage.html')
context = {
"handle": handle,
"msg": msg
}
return template.render(context, request)
def problem_page(request, handle, msg): # TODO Template!
string = '<h1>Oops, something went wrong!!</h1><p>Problem with this handle: '+str(handle)+'</p><p>Error message: <em>'+msg+'</em></p>'
return string
\ No newline at end of file
{% extends "landingpage/cmip6_headerfooter.html" %}
{% block content %}
<div class="section">
<h1>Oops, a problem occurred.</h1>
</div>
<div class="section">
<p>Something went wrong while showing the landing page for handle {{ handle }}. </p>
{% if msg %}
<p>The error message provided was: <em>{{msg}}</em></p>
{% endif %}
<p>We would be happy to <a href="mailto:handle@dkrz.de">hear from you</a> where you found the link to this handle, so we can fix the problem. Thanks a lot!</p>
</div>
{% endblock %}
\ No newline at end of file
......@@ -13,13 +13,26 @@ def entire_handle(request, prefix, suffix):
return HttpResponse(string)
def prefix_only_cmip6(request, prefix):
string = errorpages.only_prefix_cmip6(prefix)
string = errorpages.only_prefix_cmip6(request, prefix)
return HttpResponse(string)
def entire_handle_cmip6(request, prefix, suffix):
string = cmip6.entrypoint.get_html_string(request, prefix, suffix)
return HttpResponse(string)
try:
string = cmip6.entrypoint.get_html_string(request, prefix, suffix)
return HttpResponse(string)
except ValueError as e:
return problem_page_cmip6(request, prefix+'/'+suffix, e.message)
def no_handle(request):
string = errorpages.no_handle_specified(request)
return HttpResponse(string)
def problem_page(request, handle, msg=None):
string = errorpages.problem_page(request, handle, msg)
return HttpResponse(string)
def problem_page_cmip6(request, handle, msg=None):
string = errorpages.problem_page_cmip6(request, handle, msg)
return HttpResponse(string)
# TODO: Allowed methods! --> https://docs.djangoproject.com/en/1.9/topics/http/decorators/
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment