Raise specific errors on some status codes.
502448
def _raise_response_exceptions(response):
    """"""
    if not response.ok and 'www-authenticate' in response.headers:
        msg = response.headers['www-authenticate']
        if 'insufficient_scope' in msg:
            raise OAuthInsufficientScope('insufficient_scope', response.url)
        elif 'invalid_token' in msg:
            raise OAuthInvalidToken('invalid_token', response.url)
        else:
            raise OAuthException(msg, response.url)

    if response.status_code == codes.forbidden:  # pylint: disable=E1101
        raise Forbidden(_raw=response)
    elif response.status_code == codes.not_found:  # pylint: disable=E1101
        raise NotFound(_raw=response)
    else:
        try:
            response.raise_for_status()  # These should all be directly mapped
        except exceptions.HTTPError as exc:
            raise HTTPException(_raw=exc.response)
198051
def raise_right_error(response):
    """"""
    if response.status_code == 200:
        return
    if response.status_code == 500:
        raise ServerError('Clef servers are down.')
    if response.status_code == 403:
        message = response.json().get('error')
        error_class = MESSAGE_TO_ERROR_MAP[message]
        if error_class == InvalidOAuthTokenError:
            message = 'Something went wrong at Clef. Unable to retrieve user information with this token.'
        raise error_class(message)
    if response.status_code == 400:
        message = response.json().get('error')
        error_class = MESSAGE_TO_ERROR_MAP[message]
        if error_class:
            raise error_class(message)
        else:
            raise InvalidLogoutTokenError(message)
    if response.status_code == 404:
        raise NotFoundError('Unable to retrieve the page. Are you sure the Clef API endpoint is configured right?')
    raise APIError
922367
def error_retry_codes(self, value):
        """"""
        if isinstance(value, six.string_types):
            value = [int(x) for x in value.split(",")]
        self._set_option("error_retry_codes", value)
1360198
def _error(self, message, start, end=None):
        """"""
        raise errors.EfilterParseError(
            source=self.source, start=start, end=end, message=message)
11104
def _onError(self, message):
        """"""
        self.isOK = False
        if message.strip() != "":
            self.errors.append(message)
888048
def raise_remote_error(error_code: int) -> None:
    """"""
    try:
        error = next((v for k, v in ERROR_CODES.items() if k == error_code))
        raise RequestError(error)
    except StopIteration:
        raise RequestError(
            'Unknown remote error code returned: {0}'.format(error_code))
532832
def raise_http_error(cls, response):
        """"""
        response_xml = response.read()
        logging.getLogger('recurly.http.response').debug(response_xml)
        exc_class = recurly.errors.error_class_for_http_status(response.status)
        raise exc_class(response_xml)
1130029
def raise_on_errors(self):
        
        if self.errors:
            raise NotificationError(
                provider=self.provider,
                data=self.data,
                errors=self.errors,
                response=self.response,
            )
829890
def write_error(self, status_code, **kwargs):
        
        super(BaseHandler, self).write_error(status_code, **kwargs)
880046
def raise_error(error_type: str) -> None:
    """"""
    try:
        error = next((v for k, v in ERROR_CODES.items() if k in error_type))
    except StopIteration:
        error = AirVisualError
    raise error(error_type)
1154128
def _raise_error_from_response(data):
    """"""
    # Check the meta-data for why this request failed
    meta = data.get('meta')
    if meta:
        # Account for foursquare conflicts
        # see: https://developer.foursquare.com/overview/responses
        if meta.get('code') in (200, 409): return data
        exc = error_types.get(meta.get('errorType'))
        if exc:
            raise exc(meta.get('errorDetail'))
        else:
            _log_and_raise_exception('Unknown error. meta', meta)
    else:
        _log_and_raise_exception('Response format invalid, missing meta property. data', data)
914865
def _expand_error_codes(code_parts):
        """"""
        codes = set(ErrorRegistry.get_error_codes())
        expanded_codes = set()

        try:
            for part in code_parts:
                # Dealing with split-lined configurations; The part might begin
                # with a whitespace due to the newline character.
                part = part.strip()
                if not part:
                    continue

                codes_to_add = {code for code in codes
                                if code.startswith(part)}
                if not codes_to_add:
                    log.warning(
                        'Error code passed is not a prefix of any '
                        'known errors: %s', part)
                expanded_codes.update(codes_to_add)
        except TypeError as e:
            raise IllegalConfiguration(e)

        return expanded_codes
565575
def add_error_handlers(app):
    """"""

    def handle_validation_error(error):
        response = jsonify({'message': str(error)})
        response.status_code = error.status_code
        return response

    app.errorhandler(ValidationError)(handle_validation_error)
794200
def _make_error(index, code, errmsg, operation):
    
    return {
        _UINDEX: index,
        _UCODE: code,
        _UERRMSG: errmsg,
        _UOP: operation
    }
659308
def _validate_response(url, response):
    """"""
    if response['status'] not in [GooglePlaces.RESPONSE_STATUS_OK,
                                  GooglePlaces.RESPONSE_STATUS_ZERO_RESULTS]:
        error_detail = ('Request to URL %s failed with response code: %s' %
                        (url, response['status']))
        raise GooglePlacesError(error_detail)
326210
def raise_error(error):
    
    exc_type = error.get('exc_type')
    if exc_type and exc_type.startswith(ERROR_PREFIX):
        exc_type = exc_type[len(ERROR_PREFIX):]
        exc_cls = ERROR_TYPE_MAP.get(exc_type, DashiError)
    else:
        exc_cls = DashiError

    raise exc_cls(**error)
1005497
def handle_error(self, code, message_values=None, raise_error=True):
        
        try:
            if message_values is None:
                message_values = []
            message = self.error_codes.message(code).format(*message_values)
            self.log.error('Error code: {}, {}'.format(code, message))
        except AttributeError:
            self.log.error('Incorrect error code provided ({}).'.format(code))
            raise RuntimeError(1000, 'Generic Failure, see logs for more details.')
        except IndexError:
            self.log.error(
                'Incorrect message values provided for error code {} ({}).'.format(
                    code, message_values
                )
            )
            raise RuntimeError(1000, 'Generic Failure, see logs for more details.')
        if raise_error:
            raise RuntimeError(code, message)