def api_handle_error_with_json(handler):
 def api_handle_error_with_json_wrapper_fn(request, *args, **kwargs):
  try:
   return handler(request, *args, **kwargs)
  except PermissionDenied:
   raise
  except Http404:
   raise
  except Exception as e:
   logger.error('Error in JSON view: {}'.format(request.path))
   traceback.print_exc()
   return JsonResponseMessageError((_('Unexpected error: %(err)s') % {'err': e}), status=500)
 return api_handle_error_with_json_wrapper_fn

def api_handle_error_with_json ( handler ) : def api_handle_error_with_json_wrapper_fn ( request , * args , ** kwargs ) : try : return handler ( request , * args , ** kwargs ) except PermissionDenied : raise except Http404 : raise except Exception as e : logger . error ( 'Error in JSON view: {}' . format ( request . path ) ) traceback . print_exc ( ) return JsonResponseMessageError ( ( _ ( 'Unexpected error: %(err)s' ) % { 'err' : e } ) , status = 500 ) return api_handle_error_with_json_wrapper_fn
all api requests should return json objects .