def common_exceptions_400(func):
 def wrapped(request, *args, **kwargs):
  use_json = (request.is_ajax() or request.META.get('HTTP_ACCEPT', '').startswith('application/json'))
  try:
   return func(request, *args, **kwargs)
  except User.DoesNotExist:
   message = _('User does not exist.')
   if use_json:
    return JsonResponse({'error': message}, 400)
   else:
    return HttpResponseBadRequest(message)
  except AlreadyRunningError:
   message = _('Task is already running.')
   if use_json:
    return JsonResponse({'error': message}, 400)
   else:
    return HttpResponseBadRequest(message)
 return wrapped

def common_exceptions_400 ( func ) : def wrapped ( request , * args , ** kwargs ) : use_json = ( request . is_ajax ( ) or request . META . get ( 'HTTP_ACCEPT' , '' ) . startswith ( 'application/json' ) ) try : return func ( request , * args , ** kwargs ) except User . DoesNotExist : message = _ ( 'User does not exist.' ) if use_json : return JsonResponse ( { 'error' : message } , 400 ) else : return HttpResponseBadRequest ( message ) except AlreadyRunningError : message = _ ( 'Task is already running.' ) if use_json : return JsonResponse ( { 'error' : message } , 400 ) else : return HttpResponseBadRequest ( message ) return wrapped
catches common exceptions and renders matching 400 errors .