def convert_exception_to_response(get_response):
 @wraps(get_response)
 def inner(request):
  try:
   response = get_response(request)
  except Exception as exc:
   response = response_for_exception(request, exc)
  return response
 return inner

def convert_exception_to_response ( get_response ) : @ wraps ( get_response ) def inner ( request ) : try : response = get_response ( request ) except Exception as exc : response = response_for_exception ( request , exc ) return response return inner
wrap the given get_response callable in exception-to-response conversion .