Skip to content

Commit

Permalink
[FIX] Added missed 404 handling for things, improved 404 handling for…
Browse files Browse the repository at this point in the history
… placements
  • Loading branch information
s-kostyuk committed Aug 26, 2017
1 parent 85eb61e commit 88153f2
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion dpl/api/rest_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# Include DPL modules
from dpl.api import ApiGateway
from dpl.utils import JsonEnumEncoder
from . import exceptions


# Declare constants:
Expand Down Expand Up @@ -272,6 +273,13 @@ async def thing_get_handler(self, request: web.Request, token: str = None) -> we
thing = self._gateway.get_thing(token, thing_id)

return make_json_response(thing)

except exceptions.ThingNotFoundError:
return make_error_response(
message="Failed to find a thing with the specified ID",
status=404
)

except PermissionError as e:
return make_error_response(status=400, message=str(e))

Expand Down Expand Up @@ -310,11 +318,13 @@ async def placement_get_handler(self, request: web.Request, token: str = None) -

try:
return make_json_response(self._gateway.get_placement(token, placement_id))
except KeyError:

except exceptions.PlacementNotFoundError:
return make_error_response(
message="Failed to find a placement with the specified ID",
status=404
)

except PermissionError:
return make_error_response(
message="This token doesn't permit viewing of placement data",
Expand Down

0 comments on commit 88153f2

Please sign in to comment.