Attempts to look at a response's error code and return an OAuth error if
 one matches. Will return `nil` if the code isn't recognized.
434037
def specific_oauth_error(resp, error_code, context)
      description = resp.data[:error_description] || error_code

      Util.log_error("Stripe OAuth error",
                     status: resp.http_status,
                     error_code: error_code,
                     error_description: description,
                     idempotency_key: context.idempotency_key,
                     request_id: context.request_id)

      args = [error_code, description, {
        http_status: resp.http_status, http_body: resp.http_body,
        json_body: resp.data, http_headers: resp.http_headers,
      },]

      case error_code
      when "invalid_client"            then OAuth::InvalidClientError.new(*args)
      when "invalid_grant"             then OAuth::InvalidGrantError.new(*args)
      when "invalid_request"           then OAuth::InvalidRequestError.new(*args)
      when "invalid_scope"             then OAuth::InvalidScopeError.new(*args)
      when "unsupported_grant_type"    then OAuth::UnsupportedGrantTypeError.new(*args)
      when "unsupported_response_type" then OAuth::UnsupportedResponseTypeError.new(*args)
      else
        # We'd prefer that all errors are typed, but we create a generic
        # OAuthError in case we run into a code that we don't recognize.
        OAuth::OAuthError.new(*args)
      end
    end
1241396
def getErrorInfoFromResponse
      if @responseXMLdoc
         errcode = getResponseValue( :errcode )
         @errcode = errcode ? errcode : ""
         errtext = getResponseValue( :errtext )
         @errtext = errtext ? errtext : ""
         errdetail = getResponseValue( :errdetail )
         @errdetail = errdetail ? errdetail : ""
         if @errcode != "0"
            @lastError = "Error code: #{@errcode} text: #{@errtext}: detail: #{@errdetail}"
         end
      end
      @lastError
   end
981162
function checkErrors(error, response) {
        if (error) {
            return error instanceof Error ? error : new Error(error);
        }

        // Bamboo API enable plan returns 204 with empty response in case of success
        if ((response.statusCode !== 200) && (response.statusCode !== 204)) {
            return new Error("Unreachable endpoint! Response status code: " + response.statusCode);
        }

        return false;
    }
756668
def _fail_if_contains_errors(response, sync_uuid=None):
    
    if response.status_code != _HTTP_OK:
        raise RequestError(response)
    response_json = response.json()
    if sync_uuid and 'sync_status' in response_json:
        status = response_json['sync_status']
        if sync_uuid in status and 'error' in status[sync_uuid]:
            raise RequestError(response)
977390
def check(self, return_code=0):
        
        ret = self.call().return_code
        ok = ret == return_code
        if not ok:
            raise EasyProcessError(
                self, 'check error, return code is not {0}!'.format(return_code))
        return self
691742
def errors(self,
               errors: List[str],
               code: Union[int, Tuple[int, str, str]] = HTTPStatus.BAD_REQUEST,
               key: str = 'errors',
               headers: Optional[Dict[str, str]] = None,
               ):
        
        return jsonify({key: errors}), code, headers or {}
282369
def build_api_error(response, blob=None):
    
    try:
        blob = blob or response.json()
    except json.JSONDecodeError:
        blob = {}
    error_list = blob.get('errors', None)
    error = (error_list[0] if error_list else {})
    if error:
        error_id = error.get('id', '')
        error_message = error.get('message', '')
    else:
        # In the case of an OAuth-specific error, the response data is the error
        # blob, and the keys are slightly different. See
        # https://developers.coinbase.com/api/v2#error-response
        error_id = blob.get('error')
        error_message = blob.get('error_description')
    error_class = (
        _error_id_to_class.get(error_id, None) or
        _status_code_to_class.get(response.status_code, APIError))
    return error_class(response, error_id, error_message, error_list)
1124618
def validate(response)
      case response.code
      when 400 then fail Error::BadRequest, error_message(response)
      when 401 then fail Error::Unauthorized, error_message(response)
      when 403 then fail Error::Forbidden, error_message(response)
      when 404 then fail Error::NotFound, error_message(response)
      when 405 then fail Error::MethodNotAllowed, error_message(response)
      when 409 then fail Error::Conflict, error_message(response)
      when 500 then fail Error::InternalServerError, error_message(response)
      when 502 then fail Error::BadGateway, error_message(response)
      when 503 then fail Error::ServiceUnavailable, error_message(response)
      end

      handle_response(response)
    end
420058
def check_response(self, response):
        
        if response.status_code == 401:
            raise D4S2Error(UNAUTHORIZED_MESSAGE)
        if not 200 <= response.status_code < 300:
            raise D4S2Error("Request to {} failed with {}:\n{}.".format(response.url, response.status_code,
                                                                        response.text))
330883
def process_response(response)
        raise ArgumentError, 'response is null' if response.nil?

        if block_given?
          yield
        end


        # return code
        if 401 == response.code
          raise UnauthorizedError, compose_error_message(response)
        elsif 500 == response.code
          raise ServerError, compose_error_message(response)
        elsif 2 != (response.code / 100)
          raise OrientdbError, "unexpected return code, code=#{response.code}, body=#{compose_error_message(response)}"
        end

        content_type = response.headers[:content_type] if connection_library == :restclient
        content_type = response.headers['Content-Type'] if connection_library == :excon
        content_type ||= 'text/plain'

        rslt = case
          when content_type.start_with?('text/plain')
            response.body
          when content_type.start_with?('application/x-gzip')
            response.body
          when content_type.start_with?('application/json')
            ::JSON.parse(response.body)
          else
            raise OrientdbError, "unsuported content type: #{content_type}"
          end

        rslt
      end
211990
def error_info(hash)      
      if hash && (e = hash["Error"]) && (e["ErrorNumber"] || e["ErrorMessage"])
        return OpenStruct.new(:number => e["ErrorNumber"], :message => e["ErrorMessage"])
      end

      # Or wait! Some API's have a totally different way of reporting errors, great!
      if hash && (e = hash["Authentication"]) && e["Problem"] 
        return OpenStruct.new(:number => e["Problem"]["Code"], :message => e["Problem"]["Message"])
      end

      # And one more for Auth errors! With no error number, hooray. 
      if hash && (e = hash["AuthorizationState"]) && e["State"] == "failed"
        return OpenStruct.new(:number => nil, :message => "AuthorizationState: State: failed")
      end

      # And yet another way!
      if hash && (e = hash["Problem"])
        # Code/Message appear unpredictably at different keys? 
        return OpenStruct.new(:number => e["ErrorCode"] || e["Code"], :message => e["ErrorMessage"] || e["Message"])
      end

      return nil    
    end
1340358
def check_response(response)
      if response.status >= 400
        parsed_body = JSON.parse(response.body)
        raise Errors::GenericError.new(parsed_body['code'], parsed_body['message'])
      end
    end
712600
function check(err, res, body) {
    if (err) {
        return this.machine(err);
    }
    var obj;
    try {
        obj = JSON.parse(body);
    } catch (e) {
        return this.machine(new Error('Failed to parse as JSON (' + e.message + ') the text: ' + body));
    }
    if (res.statusCode !== 200) {
        return this.machine(obj);
    }
    this.machine(err, obj);
}
719560
function checkForError(resp) {
  if ('code' in resp) {
    throw errors.create(
      errors.types.BAD_REQUEST,
      errors.formatErrMsg(resp, ''),
      {body: resp}
    )
  }
  return resp
}
1162278
def _get_error(self, code, errors, indentation=0):
        
        # Init
        results = []
        lines = None
        if code is not None:
            lines = [line.strip() for line in code.split('\n')]

        for error in errors.split('\n'):
            # Strip; skip empy lines
            error = error.strip()
            if not error:
                continue
            # Separate line number from description (if we can)
            linenr, error = self._parse_error(error)
            if None in (linenr, lines):
                results.append('%s' % error)
            else:
                results.append('on line %i: %s' % (linenr, error))
                if linenr > 0 and linenr < len(lines):
                    results.append('  %s' % lines[linenr - 1])

        # Add indentation and return
        results = [' ' * indentation + r for r in results]
        return '\n'.join(results)
1283589
def authorization_error_class(response):
    
    message = response.headers.get("www-authenticate")
    if message:
        error = message.replace('"', "").rsplit("=", 1)[1]
    else:
        error = response.status_code
    return _auth_error_mapping[error](response)
1230909
function error(code, msg) {
    var err = new Error(msg);
    err.errno = code;
    return err;
}