Skip to content

Commit

Permalink
error logging
Browse files Browse the repository at this point in the history
  • Loading branch information
tef committed Jul 31, 2012
1 parent 16cad78 commit b0837ab
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
6 changes: 3 additions & 3 deletions py/glyph/resource/base.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import types
import traceback

from urllib import quote_plus, unquote_plus

Expand Down Expand Up @@ -113,9 +114,8 @@ def handle(self,request, router):
# no instance found, use default handler
attr = self.default_method(verb)

except StandardError:
import traceback
traceback.print_exc()
except StandardError as e:
router.log_error(e, traceback.format_exc())
raise BadRequest()

return Handler.call(attr, request, router)
Expand Down
17 changes: 12 additions & 5 deletions py/glyph/resource/router.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import weakref
import sys
import traceback

from werkzeug.utils import redirect as Redirect
from werkzeug.wrappers import Request, Response
Expand Down Expand Up @@ -42,15 +44,20 @@ def __call__(self, environ, start_response):
except (StopIteration, GeneratorExit, SystemExit, KeyboardInterrupt):
raise
except HTTPException as r:
import traceback;
traceback.print_exc()
response = r
self.log_error(r, traceback.format_exc())
except Exception as e:
import traceback;
traceback.print_exc()
response = Response(traceback.format_exc(), status='500 not ok')
trace = traceback.format_exc()
self.log_error(e, trace)
response = self.error_response(e, trace)
return response(environ, start_response)

def log_error(self, exception, trace):
print >> sys.stderr, trace

def error_response(self, exception, trace):
return Response(trace, status='500 not ok (%s)'%exception)


def url_mapper(self, path):
try:
Expand Down

0 comments on commit b0837ab

Please sign in to comment.