Return a JSON result after an HTTP Request.

        Process the response of an HTTP Request and make it a JSON error if
        it failed. Otherwise return the response's content.
506908
def _process_response(self):
        
        response = self.conn.getresponse()
        if response.status == 200 or response.status == 201:
            data = response.read()
        else:
            data = {
                "error":  {
                    "code": response.status,
                    "reason": response.reason,
                    "data": response.read()
                }
            }

        return data
906770
def _request_process_json_bulk(self, response_data):
        
        status = 'Failure'
        data = response_data.get(self.request_entity, [])
        if data:
            status = 'Success'
        return data, status
453251
def render_json_response(self, context_dict, status=200):
        
        json_context = json.dumps(
            context_dict,
            cls=DjangoJSONEncoder,
            **self.get_json_dumps_kwargs()
        ).encode(u'utf-8')
        return HttpResponse(
            json_context,
            content_type=self.get_content_type(),
            status=status
        )
1300188
def request(self, url, method, data=None):
        
        method = getattr(requests, method)
        response = method(
            url,
            headers=self.headers,
            data=self.process_json_for_cloudflare(data) if data else None
        )
        content = response.json()
        if response.status_code != 200:
            print(content)
            raise requests.HTTPError(content['message'])
        return content
678232
def after_request(self, response):
        
        if response is not None and request is not None:
            # When used as response processor, only run if we are requesting
            # anything but a static resource.
            if request.endpoint in [None, "static"]:
                return response
        self.compile()
        return response
1294200
function (err, data) {
      debug(`${service}.${method} response:`, err || {
        status: data && data.status,
        size: data && JSON.stringify(data).length
      });
      if (err) return next(err.cause || err);

      res.data = data;

      if (!data) {
        debug(`No content returned for '${req.url}'`);
        res.status(statusCodes.noContent);
      } else if (method === 'create') {
        res.status(statusCodes.created);
      }

      return next();
    }
710253
def handle_get(self):
        

        code = 400
        message, explain = BaseHTTPRequestHandler.responses[code]

        response = http_server.DEFAULT_ERROR_MESSAGE % \
            {
             'code' : code,
             'message' : message,
             'explain' : explain
            }
        response = response.encode('utf-8')
        print('Status: %d %s' % (code, message))
        print('Content-Type: %s' % http_server.DEFAULT_ERROR_CONTENT_TYPE)
        print('Content-Length: %d' % len(response))
        print()
        sys.stdout.flush()
        sys.stdout.buffer.write(response)
        sys.stdout.buffer.flush()
930103
def getresponse(self):
        
        resp = self.http.getresponse()
        self.log.info("resp is %s", str(resp))
        if resp.status < 400:
            return resp
        else:
            errtext = resp.read()
            content_type = resp.getheader('Content-Type', 'text/plain')
            raise HttpError(code=resp.status, content_type=content_type, content=errtext)
481471
def _make_request(self, request):
        
        # TODO: I'm sure all kinds of error checking needs to go here
        try:
            response_raw = urllib2.urlopen(request)
        except urllib2.HTTPError, e:
            print e.read()
            raise

        response_str = response_raw.read()
        response = json.loads(response_str)

        self._last_request = request
        self._last_response = response_raw
        self._last_response_str = response_str
        return response
921631
def _get_json(self, url):
        
        self.log.info(u"/GET " + url)
        r = requests.get(url)
        if hasattr(r, 'from_cache'):
            if r.from_cache:
                self.log.info("(from cache)")
        if r.status_code != 200:
            throw_request_err(r)

        return r.json()
53290
def get_json_response(self):
        
        self.json_response = self.get_response().json()
        if self.json_response is not None:
            error_code = self.json_response.get("errcode", None)
            self.call_status = True if error_code == 0 else False
        return self.json_response
183257
def _request(self, method, url, query_or_data=None, **kwargs):
        

        if query_or_data is None:
            query_or_data = {}

        request_method = getattr(self, '_http_{0}'.format(method))
        response = retry_request(self)(request_method)(url, query_or_data, **kwargs)

        if self.raw_mode:
            return response

        if response.status_code >= 300:
            error = get_error(response)
            if self.raise_errors:
                raise error
            return error

        # Return response object on NoContent
        if response.status_code == 204 or not response.text:
            return response

        return ResourceBuilder(
            self,
            self.default_locale,
            response.json()
        ).build()
1196116
def error_response(self, error, mimetype='application/json', status=400,
            **kwargs):
        
        return HttpResponse(json.dumps(error), mimetype=mimetype,
                status=status, **kwargs)
1294694
def __ProcessHttpResponse(self, method_config, http_response, request):
        """"""
        if http_response.status_code not in (http_client.OK,
                                             http_client.CREATED,
                                             http_client.NO_CONTENT):
            raise exceptions.HttpError.FromResponse(
                http_response, method_config=method_config, request=request)
        if http_response.status_code == http_client.NO_CONTENT:
            # TODO(craigcitro): Find out why _replace doesn't seem to work
            # here.
            http_response = http_wrapper.Response(
                info=http_response.info, content='{}',
                request_url=http_response.request_url)

        content = http_response.content
        if self._client.response_encoding and isinstance(content, bytes):
            content = content.decode(self._client.response_encoding)

        if self.__client.response_type_model == 'json':
            return content
        response_type = _LoadClass(method_config.response_type_name,
                                   self.__client.MESSAGES_MODULE)
        return self.__client.DeserializeMessage(response_type, content)
825433
def _http_call(self, url, method, data=None, **kwargs):
        
        response = self._http_response(url, method, data=data, **kwargs)
        if not response.content:
            return {}

        return response.json()
833399
def _process_response(response):
        
        if response.status_code == 404:
            raise Trovebox404Error("HTTP Error %d: %s" %
                                   (response.status_code, response.reason))
        try:
            json_response = response.json()
            code = json_response["code"]
            message = json_response["message"]
        except (ValueError, KeyError):
            # Response wasn't Trovebox JSON - check the HTTP status code
            if 200 <= response.status_code < 300:
                # Status code was valid, so just reraise the exception
                raise
            else:
                raise TroveboxError("HTTP Error %d: %s" %
                                    (response.status_code, response.reason))

        if 200 <= code < 300:
            return json_response
        elif (code == DUPLICATE_RESPONSE["code"] and
               DUPLICATE_RESPONSE["message"] in message):
            raise TroveboxDuplicateError("Code %d: %s" % (code, message))
        else:
            raise TroveboxError("Code %d: %s" % (code, message))
673808
def result(body, type)
      result = JSON.load(body)

      case type
      when 'api/send'
        body
      when 'api/status'
        body
      when 'api/cancel'
        body
      end

    end