def _wrapper(request, *args, **kwargs): import servers.web2.error.views as web_error try: logs.begin(saveLog=stampedAPIProxy.api._logsDB.saveLog, saveStat=stampedAPIProxy.api._statsDB.addStat, requestData=request, nodeName=stampedAPIProxy.api.node_name) logs.info("%s %s" % (request.method, request.path)) subkwargs = kwargs if schema is not None: parse_kwargs = parse_request_kwargs or {} django_kwargs = {} if parse_django_kwargs: django_kwargs = kwargs or {} subkwargs = {} result = parse_request(request, schema(), django_kwargs, overflow=ignore_extra_params, **parse_kwargs) subkwargs['schema'] = result response = fn(request, *args, **subkwargs) logs.info("End request: Success") if no_cache: expires = (dt.datetime.utcnow() - dt.timedelta(minutes=10)).ctime() cache_control = 'no-cache' elif utils.is_ec2(): expires = (dt.datetime.utcnow() + dt.timedelta(minutes=60)).ctime() cache_control = 'max-age=600' else: # disable caching for local development / debugging expires = (dt.datetime.utcnow() - dt.timedelta(minutes=10)).ctime() cache_control = 'max-age=0' response['Expires'] = expires response['Cache-Control'] = cache_control return response except urllib2.HTTPError, e: logs.warning("%s Error: %s" % (e.code, e)) logs.warning(utils.getFormattedException()) if e.code == 404: return web_error.error_404(request) elif e.code >= 500: return web_error.error_500(request) raise # invoke django's default 500 handler
logs.error(response.status_code) return response except StampedDuplicationError as e: logs.warning("409 Error: %s" % (e.msg)) logs.warning(utils.getFormattedException()) response = HttpResponse("already_exists", status=409) logs.error(response.status_code) return response except StampedUnavailableError as e: logs.warning("404 Error: %s" % (e.msg)) logs.warning(utils.getFormattedException()) return web_error.error_404(request) #response = HttpResponse("not_found", status=404) #logs.error(response.status_code) #return response except Exception as e: logs.warning("500 Error: %s" % e) logs.warning(utils.getFormattedException()) utils.printException() logs.error(500) raise # invoke django's default 500 handler #response = HttpResponse("internal server error", status=500) #return response