Wrap `get_data`, when missing data, raise BadRequest.
507171
def get_data_or_404(model, instance_id, kind=''):
    
    data = get_data(model, instance_id, kind)

    if not data:
        return abort(404)

    return data
137052
def get(self, project):
        """"""
        try:
            data = self.request(project + '/')
        except:
            raise
        if not isinstance(data, clam.common.data.CLAMData):
            raise Exception("Unable to retrieve CLAM Data")
        else:
            return data
766839
def _req(self, endpoint, get_data=dict(), post_data=dict()):

        

        if get_data:
            request_parameter = "{}?{}".format(endpoint, urlencode(get_data))
        else:
            request_parameter = endpoint

        try:
            encdata = urlencode(post_data, True).encode('utf-8')
            response = self.oauth.request(request_parameter, data=encdata)
            self._checkResponseForErrors(response)
        except HTTPError as e:
            raise DeviantartError(e)

        return response
565656
def _handle_dump_unknown(self, data, original):
        """"""
        for key, val in original.items():
            if key not in self.fields:
                data[key] = val
        return data
13762
def transform_data(self, data, request=None, response=None, context=None):
        transform = self.transform
        if hasattr(transform, 'context'):
            self.transform.context = context
        """"""
        if transform and not (isinstance(transform, type) and isinstance(data, transform)):
            if self._params_for_transform:
                return transform(data, **self._arguments(self._params_for_transform, request, response))
            else:
                return transform(data)
        return data
400685
def process_request(self, request):
        """"""
        try:
            request = Request.from_json(request.read().decode())
        except ValueError:
            raise ClientError('Data is not valid JSON.')
        except KeyError:
            raise ClientError('Missing mandatory field in request object.')
        except AttributeNotProvided as exc:
            raise ClientError('Attribute not provided: %s.' % exc.args[0])

        (start_wall_time, start_process_time) = self._get_times()
        answers = self.router_class(request).answer()
        self._add_times_to_answers(answers, start_wall_time, start_process_time)

        answers = [x.as_dict() for x in answers]
        return self.make_response('200 OK',
                                  'application/json',
                                  json.dumps(answers)
                                 )
205830
def get_failed_requests(self, results):
        
        data = {member['guid']: member for member in results}
        for request in self.requests:
            if request['guid'] not in data:
                yield request
159495
def request(self, service, data):
        
        _res = self._request(service, data)
        res = _res.json()[0][0]
        if res["success"] == True:
            return res["result"]
        else:
            err_msg = res["errmsg"]
            raise Exception("Request not successful: '{0}'".format(err_msg))
994798
def _raise_for_remote_status(url: str, data: dict) -> None:
    """"""
    if data.get('errorType') and data['errorType'] > 0:
        raise_remote_error(data['errorType'])

    if data.get('statusCode') and data['statusCode'] != 200:
        raise RequestError(
            'Error requesting data from {0}: {1} {2}'.format(
                url, data['statusCode'], data['message']))
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
935874
def append(self, request, response):
        """"""
        request = self._before_record_request(request)
        if not request:
            return
        # Deepcopy is here because mutation of `response` will corrupt the
        # real response.
        response = copy.deepcopy(response)
        response = self._before_record_response(response)
        if response is None:
            return
        self.data.append((request, response))
        self.dirty = True
986094
def _on_request(self, name, args):
        """"""
        if IS_PYTHON3:
            name = decode_if_bytes(name)
        handler = self._request_handlers.get(name, None)
        if not handler:
            msg = self._missing_handler_error(name, 'request')
            error(msg)
            raise ErrorResponse(msg)

        debug('calling request handler for "%s", args: "%s"', name, args)
        rv = handler(*args)
        debug("request handler for '%s %s' returns: %s", name, args, rv)
        return rv
1371552
def get_data(self, request, key='params'):
        
        return request.session.get('%s:%s' % (constants.SESSION_KEY, key))
94880
def _get(self, url):
        """"""
        req = requests.get(RequestHandler.BASE_URL + url, headers=self.headers)
        status_code = req.status_code
        if status_code == requests.codes.ok:
            return req
        elif status_code == requests.codes.bad:
            raise APIErrorException('Invalid request. Check parameters.')
        elif status_code == requests.codes.forbidden:
            raise APIErrorException('This resource is restricted')
        elif status_code == requests.codes.not_found:
            raise APIErrorException('This resource does not exist. Check parameters')
        elif status_code == requests.codes.too_many_requests:
            raise APIErrorException('You have exceeded your allowed requests per minute/day')
235265
def expect_invalid_resp_data(data=''):
    """"""
    try:
        yield
    except (ValueError, TypeError, IndexError, AttributeError,
            KeyError) as err:
        msg = ('Invalid smt response data: %s. Error: %s' %
               (data, six.text_type(err)))
        LOG.error(msg)
        raise exception.SDKInternalError(msg=msg)
1113139
def get_data(self, url, type=GET, params=None):
        
        if params is None:
            params = dict()

        req = self.__perform_request(url, type, params)
        if req.status_code == 204:
            return True

        if req.status_code == 404:
            raise NotFoundError()

        try:
            data = req.json()
        except ValueError as e:
            raise JSONReadError(
                'Read failed from API: %s' % str(e)
            )

        if not req.ok:
            msg = [data[m] for m in ("id", "message") if m in data][1]
            raise DataReadError(msg)

        return data
149226
def get(self, url, data=None, params=None):
        
        return self.request("get", url, data, params)