Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions mapit/shortcuts.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ def json_500(request):
return output_json({'error': "Sorry, something's gone wrong."}, code=500)


def json_404(request, *args, **kwargs):
return output_json({'error': "Not found."}, code=404)


def set_timeout(format):
cursor = connection.cursor()
timeout = 10000 if format == 'html' else 10000
Expand Down
7 changes: 7 additions & 0 deletions mapit/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from django.conf import settings
from django.shortcuts import render

from mapit.shortcuts import json_404
from mapit.utils import re_number as number
from mapit.views import areas, postcodes

Expand Down Expand Up @@ -58,6 +59,12 @@
re_path(r'^areas/(?P<name>.+?)%s$' % map_format_end, areas.areas_by_name),
re_path(r'^areas$', areas.deal_with_POST, {'call': 'areas'}),
re_path(r'^code/(?P<code_type>[^/]+)/(?P<code_value>[^/]+?)%s$' % format_end, areas.area_from_code),

# Catch API-shaped URLs that didn't match any of the specific patterns
# above and return a JSON 404 instead of Django's HTML one. Non-API URLs
# still fall through to the project-level 404 page.
re_path(r'^(?:postcode|area|areas|point|nearest|code)(?:/.*|\.[a-z]+)?$', json_404),
re_path(r'^(?:generations|types)(?:\.[a-z]+)?$', json_404),
]

# Include app-specific urls
Expand Down