Commit 47576e45 authored by Christos Stavrakakis's avatar Christos Stavrakakis
Browse files

snf_django: Propper logging of unexpected errors

Extend logging of unexpected errors, in 'api_method' decorator to
include the request and the status code in the log record, in order to
be properly displayed by Django's AdminMailHandler.
parent e933347b
......@@ -30,7 +30,7 @@
# documentation are those of the authors and should not be
# interpreted as representing official policies, either expressed
# or implied, of GRNET S.A.
import sys
from functools import wraps
from traceback import format_exc
from time import time
......@@ -119,19 +119,32 @@ def api_method(http_method=None, token_required=True, user_required=True,
# Fill in response variables
update_response_headers(request, response)
return response
except faults.Fault, fault:
except faults.Fault as fault:
if fault.code >= 500:
logger.exception("API ERROR")
logger.error("Unexpected API Error: %s", request.path,
exc_info=sys.exc_info(),
extra={
"status_code": fault.code,
"request": request})
return render_fault(request, fault)
except AstakosClientException as err:
fault = faults.Fault(message=err.message,
details=err.details,
code=err.status)
if fault.code >= 500:
logger.exception("Astakos ERROR")
logger.error("Unexpected AstakosClient Error: %s",
request.path,
exc_info=sys.exc_info(),
extra={
"status_code": fault.code,
"request": request})
return render_fault(request, fault)
except:
logger.exception("Unexpected ERROR")
logger.error("Internal Server Error: %s", request.path,
exc_info=sys.exc_info(),
extra={
"status_code": '500',
"request": request})
fault = faults.InternalServerError("Unexpected error")
return render_fault(request, fault)
return csrf.csrf_exempt(wrapper)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment