From 2578fd58178ee5ad76584a777e30467566de8644 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Sat, 22 Feb 2014 22:08:46 -0500 Subject: [PATCH] More gracefully fail when client goes off the rails. A client with certain URLs that go off the end of the valid world was causing exceptions to be thrown not of the set of 'tame' errors. Denote them as 404 since that is the nature of the failure. --- confluent/pluginapi.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/confluent/pluginapi.py b/confluent/pluginapi.py index 6d5d8391..7733102d 100644 --- a/confluent/pluginapi.py +++ b/confluent/pluginapi.py @@ -27,7 +27,10 @@ pluginmap = {} def nested_lookup(nestdict, key): - return reduce(dict.__getitem__, key, nestdict) + try: + return reduce(dict.__getitem__, key, nestdict) + except TypeError: + raise exc.NotFoundException("Invalid element requested") def load_plugins(): @@ -155,6 +158,8 @@ def enumerate_node_collection(collectionpath, configmanager): raise exc.NotFoundException("Invalid element requested") del collectionpath[0:2] collection = nested_lookup(noderesources, collectionpath) + if not isinstance(collection, dict): + raise exc.NotFoundException("Invalid element requested") return iterate_resources(collection)