Skip to content

Commit

Permalink
Better error handling for capakey. Refs #36
Browse files Browse the repository at this point in the history
  • Loading branch information
Koen Van Daele committed Feb 2, 2016
1 parent 5377f41 commit 66f48a0
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 10 deletions.
6 changes: 6 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
0.4.1 (2016-02-02)
------------------

- Better error handling for capakey views. Generate HTTP 404 Not Found instead
of HTTP 500 Internal Server Error. (#36)

0.4.0 (2016-01-25)
------------------

Expand Down
12 changes: 12 additions & 0 deletions crabpy_pyramid/tests/test_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,18 @@ def test_list_kadastrale_afdelingen_by_gemeente(self):
res = self.testapp.get('/capakey/gemeenten/11001/afdelingen')
self.assertEqual('200 OK', res.status)

def test_list_kadastrale_afdelingen(self):
res = self.testapp.get('/capakey/afdelingen')
self.assertEqual('200 OK', res.status)

def test_get_kadastrale_afdeling_by_id(self):
res = self.testapp.get('/capakey/afdelingen/11001')
self.assertEqual('200 OK', res.status)

def test_get_kadastrale_afdeling_by_unexisting_id(self):
res = self.testapp.get('/capakey/afdelingen/99999', status=404)
self.assertEqual('404 Not Found', res.status)

def test_list_secties_by_afdeling(self):
res = self.testapp.get('/capakey/afdelingen/11001/secties')
self.assertEqual('200 OK', res.status)
Expand Down
36 changes: 30 additions & 6 deletions crabpy_pyramid/views/capakey.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
from pyramid.view import view_config
from crabpy_pyramid.utils import range_return

from crabpy.gateway.exception import GatewayResourceNotFoundException

from pyramid.httpexceptions import HTTPNotFound


@view_config(route_name='list_gemeenten', renderer='capakey_listjson', accept='application/json')
def list_gemeenten(request):
Gateway = request.capakey_gateway()
Expand All @@ -18,7 +23,10 @@ def list_gemeenten(request):
def get_gemeente_by_niscode(request):
Gateway = request.capakey_gateway()
gemeente_id = int(request.matchdict.get('gemeente_id'))
return Gateway.get_gemeente_by_id(gemeente_id)
try:
return Gateway.get_gemeente_by_id(gemeente_id)
except GatewayResourceNotFoundException:
return HTTPNotFound()


@view_config(
Expand Down Expand Up @@ -46,7 +54,10 @@ def list_kadastrale_afdelingen(request):
def get_kadastrale_afdeling_by_id(request):
Gateway = request.capakey_gateway()
afdeling_id = request.matchdict.get('afdeling_id')
return Gateway.get_kadastrale_afdeling_by_id(afdeling_id)
try:
return Gateway.get_kadastrale_afdeling_by_id(afdeling_id)
except GatewayResourceNotFoundException:
return HTTPNotFound()


@view_config(
Expand All @@ -68,7 +79,10 @@ def get_sectie_by_id_and_afdeling(request):
Gateway = request.capakey_gateway()
afdeling_id = request.matchdict.get('afdeling_id')
sectie_id = request.matchdict.get('sectie_id')
return Gateway.get_sectie_by_id_and_afdeling(sectie_id, afdeling_id)
try:
return Gateway.get_sectie_by_id_and_afdeling(sectie_id, afdeling_id)
except GatewayResourceNotFoundException:
return HTTPNotFound()


@view_config(
Expand All @@ -95,7 +109,10 @@ def get_perceel_by_sectie_and_id(request):
sectie_id = request.matchdict.get('sectie_id')
afdeling_id = request.matchdict.get('afdeling_id')
sectie = Gateway.get_sectie_by_id_and_afdeling(sectie_id, afdeling_id)
return Gateway.get_perceel_by_id_and_sectie(perceel_id, sectie)
try:
return Gateway.get_perceel_by_id_and_sectie(perceel_id, sectie)
except GatewayResourceNotFoundException:
return HTTPNotFound()


@view_config(
Expand All @@ -106,7 +123,10 @@ def get_perceel_by_capakey(request):
Gateway = request.capakey_gateway()
capakey = str(request.matchdict.get('capakey1'))+'/'\
+ str(request.matchdict.get('capakey2'))
return Gateway.get_perceel_by_capakey(capakey)
try:
return Gateway.get_perceel_by_capakey(capakey)
except GatewayResourceNotFoundException:
return HTTPNotFound()


@view_config(
Expand All @@ -116,4 +136,8 @@ def get_perceel_by_capakey(request):
def get_perceel_by_percid(request):
Gateway = request.capakey_gateway()
percid = request.matchdict.get('percid')
return Gateway.get_perceel_by_percid(percid)
try:
return Gateway.get_perceel_by_percid(percid)
except GatewayResourceNotFoundException:
return HTTPNotFound()

8 changes: 4 additions & 4 deletions development.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ use = egg:crabpy_pyramid

pyramid.reload_templates = true
pyramid.debug_authorization = false
pyramid.debug_notfound = false
pyramid.debug_routematch = false
pyramid.debug_notfound = true
pyramid.debug_routematch = true
pyramid.default_locale_name = en
#pyramid.includes =
# pyramid_debugtoolbar
pyramid.includes =
pyramid_debugtoolbar

crabpy.capakey.include = False
crabpy.capakey.user = USER
Expand Down

0 comments on commit 66f48a0

Please sign in to comment.