diff --git a/src/c3nav/routing/api.py b/src/c3nav/routing/api.py index 0f85a444..b8332ef5 100644 --- a/src/c3nav/routing/api.py +++ b/src/c3nav/routing/api.py @@ -1,9 +1,11 @@ +from django.utils.translation import ugettext_lazy as _ from rest_framework.decorators import list_route from rest_framework.response import Response from rest_framework.viewsets import ViewSet from c3nav.mapdata.models.access import AccessPermission from c3nav.mapdata.utils.locations import visible_locations_for_request +from c3nav.routing.exceptions import LocationUnreachable, NoRouteFound, NotYetRoutable from c3nav.routing.forms import RouteForm from c3nav.routing.router import Router @@ -19,9 +21,22 @@ class RoutingViewSet(ViewSet): 'errors': form.errors, }) - route = Router.load().get_route(origin=form.cleaned_data['origin'], - destination=form.cleaned_data['destination'], - permissions=AccessPermission.get_for_request(request)) + try: + route = Router.load().get_route(origin=form.cleaned_data['origin'], + destination=form.cleaned_data['destination'], + permissions=AccessPermission.get_for_request(request)) + except NotYetRoutable: + return Response({ + 'error': _('Not yet routable, try again shortly.'), + }) + except LocationUnreachable: + return Response({ + 'error': _('Unreachable location.'), + }) + except NoRouteFound: + return Response({ + 'error': _('No route found.'), + }) return Response({ 'request': { diff --git a/src/c3nav/site/static/site/js/c3nav.js b/src/c3nav/site/static/site/js/c3nav.js index 4d8cd559..b51b9302 100644 --- a/src/c3nav/site/static/site/js/c3nav.js +++ b/src/c3nav/site/static/site/js/c3nav.js @@ -238,6 +238,11 @@ c3nav = { }, _route_loaded: function(data, nofly) { var $route = $('#route-summary'); + if (data.error && $route.is('.loading')) { + $route.find('span').text(data.error); + $route.removeClass('loading'); + return; + } if ($route.attr('data-origin') !== String(data.request.origin) || $route.attr('data-destination') !== String(data.request.destination)) { // loaded too late, information no longer needed return;