Shortcut API for HTTP 400 `Bad Request` response.

        Args:
            errors (list): Response key/value data.

        Returns:
            WSResponse Instance.
503594
def bad_request(cls, errors=None):
        
        if cls.expose_status:  # pragma: no cover
            cls.response.content_type = 'application/json'
            cls.response._status_line = '400 Bad Request'

        return cls(400, errors=errors).to_json
1236911
def badRequestMethod(self, environ, start_response):
        
        response = "400 Bad Request\n\nTo access this PyAMF gateway you " \
            "must use POST requests (%s received)" % environ['REQUEST_METHOD']

        start_response('400 Bad Request', [
            ('Content-Type', 'text/plain'),
            ('Content-Length', str(len(response))),
            ('Server', gateway.SERVER_NAME),
        ])

        return [response]
298912
def error_message
      response_body = JSON(response.body) rescue response.inspect
      {request_curl: as_curl, response_body: response_body}
    end
129253
def check_response(res):
    
    try:
        res.raise_for_status() # Alternative is res.ok
    except Exception as exc:
        # Bad response code, e.g. if adding an edge with nodes that doesn't exist
        try:
            err_info = res.json()
            err_msg = err_info['message'] # or 'localizeMessage'
        except ValueError:
            err_msg = res.text[:40] # Take the first 40 chars of the response
        except KeyError:
            err_msg = res.text[:40] + ("(No 'message' in err_info dict: %s"
                                       % list(err_info.keys()))
        exc.args += (err_msg,)
        raise exc
623853
def errors(self):
        
        try:
            return self.__dict__['errors']
        except KeyError:
            pass

        suberrors = dict()
        for err in self.response_doc.findall('error'):
            field = err.attrib['field']
            symbol = err.attrib['symbol']
            message = err.text
            sub_err = self.Suberror(field, symbol, message)

            # If the field exists, we need to turn the suberror
            # into a list of suberrors
            if field in suberrors:
                if type(suberrors[field]) != list:
                    suberrors[field] = [suberrors[field]]
                suberrors[field].append(sub_err)
            else:
                suberrors[field] = sub_err

        self.__dict__['errors'] = suberrors
        return suberrors
132799
def bad_request(request, template_name='400.html'):
    

    response = render_in_page(request, template_name)

    if response:
        return response

    try:
        template = loader.get_template(template_name)
    except TemplateDoesNotExist:
        return http.HttpResponseBadRequest('<h1>Bad Request (400)</h1>', content_type='text/html')
    return http.HttpResponseBadRequest(template.render(Context({})))
14692
def build_response(cls, code=Status.SYSTEM_ERROR, errors=None):
        
        errors = [errors] if not isinstance(errors, list) else errors
        return cls(code, errors)
719560
function checkForError(resp) {
  if ('code' in resp) {
    throw errors.create(
      errors.types.BAD_REQUEST,
      errors.formatErrMsg(resp, ''),
      {body: resp}
    )
  }
  return resp
}
532782
function clientError(err, res) {
  log('error', err.message, { stack: err.stack });
  // They know it's a 400 already, we don't need to repeat the fact that its an error.
  const message = removePrefix(err.message, ':'),
    code = 400;

  sendDefaultResponseForCode(code, message, res);
}
518180
def __error_middleware(self, res, res_json):
        
        if(res.status_code in [400, 401, 402, 403, 404, 405, 406, 409]):
            err_dict = res_json.get('error', {})
            raise UpCloudAPIError(error_code=err_dict.get('error_code'),
                                  error_message=err_dict.get('error_message'))

        return res_json
729117
def _conditional_error(self, req, response):
        
        if not req or req.sent_headers:
            return

        try:
            req.simple_response(response)
        except errors.FatalSSLAlert:
            pass
        except errors.NoSSLError:
            self._handle_no_ssl(req)
1326945
def dispatch_error(self, err):
        '''
        
        '''
        try:
            data = {'error': [l for l in err.args]}
            body = self._meta.formatter.format(data)
        except Exception as ex:
            data = {'error': str(err)}
            body = self._meta.formatter.format(data)

        status = getattr(err, 'status', 500)
        return self.build_http_response(body, status=status)
1106753
def transform_error2_response(error)
        response = ["#{error.message}: #{error.http_body}", error.http_code]
        def response.body
          self[0]
        end
        def response.code
          self[1]
        end
        response
      end
315479
def error_code(self, code):
		

		context = {
			'error_title': "Damn error page %i" % code,
			'error_header': "What has happened?",
			'error_footer': "WHY!?!?!",
			'error_messages': {
				('Error %i' % code): self.__message__(code)
			}
		}
		return WWebTemplateResponse(WTemplateText(self.__error_template__()), context=context)
568886
def err_response(reqid, code, msg, data=None):
    
    err = { "code": code, "message": msg }
    if data:
        err["data"] = data
    return { "jsonrpc": "2.0", "id": reqid, "error": err }
755569
def rpc_message_to_error(rpc_error, request):
    
    # Try to get the error by direct look-up, otherwise regex
    cls = rpc_errors_dict.get(rpc_error.error_message, None)
    if cls:
        return cls(request)

    for msg_regex, cls in rpc_errors_re:
        m = re.match(msg_regex, rpc_error.error_message)
        if m:
            capture = int(m.group(1)) if m.groups() else None
            return cls(request, capture=capture)

    # Some errors are negative:
    # * -500 for "No workers running",
    # * -503 for "Timeout"
    #
    # We treat them as if they were positive, so -500 will be treated
    # as a `ServerError`, etc.
    cls = base_errors.get(abs(rpc_error.error_code))
    if cls:
        return cls(request, rpc_error.error_message)

    return RPCError(request, rpc_error.error_message, rpc_error.error_code)
302626
def _handle_response(self, response):
        
        status = response.status_code
        if status == 400:
          msg = u"bad request"
          raise exceptions.BadRequest(status, msg)
        elif status == 401:
          msg = u"authorization failed user:%s" % (self.sk_user)
          raise exceptions.Unauthorized(status, msg)
        elif status == 404:
          raise exceptions.NotFound()
        elif status == 422:
          msg = u"bad request"
          raise exceptions.BadRequest(status, msg)
        elif status in range(400, 500):
          msg = u"unexpected bad request"
          raise exceptions.BadRequest(status, msg) 
        elif status in range(500, 600):
          raise exceptions.ServerError()
        return response