Skip to content

Commit 985e540

Browse files
committed
imported patch api_docs_404
1 parent b417caf commit 985e540

File tree

1 file changed

+14
-6
lines changed
  • samples/api-python-client-doc

1 file changed

+14
-6
lines changed

samples/api-python-client-doc/main.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
from apiclient.anyjson import simplejson
3434
from apiclient import discovery
35+
from apiclient.errors import HttpError
3536
from google.appengine.api import memcache
3637
from google.appengine.ext import webapp
3738
from google.appengine.ext.webapp import template
@@ -97,13 +98,20 @@ class ResourceHandler(webapp.RequestHandler):
9798

9899
def get(self, service_name, version, collection):
99100
http = httplib2.Http(memcache)
100-
resource = discovery.build(service_name, version, http=http)
101+
try:
102+
resource = discovery.build(service_name, version, http=http)
103+
except:
104+
return self.error(404)
101105
# descend the object path
102106
if collection:
103-
path = collection.split('/')
104-
if path:
105-
for method in path:
106-
resource = getattr(resource, method)()
107+
try:
108+
path = collection.split('/')
109+
if path:
110+
for method in path:
111+
resource = getattr(resource, method)()
112+
except:
113+
return self.error(404)
114+
107115
page = _render(resource)
108116

109117
collections = []
@@ -134,7 +142,7 @@ def main():
134142
(r'/_gadget/', GadgetHandler),
135143
(r'/([^\/]*)/([^\/]*)(?:/(.*))?', ResourceHandler),
136144
],
137-
debug=True)
145+
debug=False)
138146
util.run_wsgi_app(application)
139147

140148

0 commit comments

Comments
 (0)