### Home Classes Methods

### In Files

- lib/github_api/error/service_error.rb

### Parent

Github::Error::GithubError

### Methods

- ::errors
- ::http_status_code
- ::new
- #decode_body
- #parse_body
- #parse_response

### Included Modules

- Github::Jsonable

### Class/Module Index

Quicksearch

- Github
- Github::API
- Github::Activity
- Github::Activity::Events
- Github::Activity::Notifications
- Github::Activity::Starring
- Github::Activity::Watching
- Github::ApiFactory
- Github::Arguments
- Github::Authorization
- Github::Authorizations
- Github::AutoloadHelper
- Github::Client
- Github::Configuration
- Github::Connection
- Github::Constants
- Github::CoreExt
- Github::CoreExt::OrderedHash
- Github::Descendants
- Github::Emojis
- Github::Error
- Github::Error::BadRequest
- Github::Error::ClientError
- Github::Error::Forbidden
- Github::Error::GithubError
- Github::Error::InternalServerError
- Github::Error::InvalidOptions
- Github::Error::NotAcceptable
- Github::Error::NotFound
- Github::Error::RequiredParams
- Github::Error::ServiceError
- Github::Error::ServiceUnavailable
- Github::Error::Unauthorized
- Github::Error::UnknownValue
- Github::Error::UnprocessableEntity
- Github::Error::Validations
- Github::Gists
- Github::Gists::Comments
- Github::GitData
- Github::GitData::Blobs
- Github::GitData::Commits
- Github::GitData::References
- Github::GitData::Tags
- Github::GitData::Trees
- Github::Gitignore
- Github::Issues
- Github::Issues::Assignees
- Github::Issues::Comments
- Github::Issues::Events
- Github::Issues::Labels
- Github::Issues::Milestones
- Github::Jsonable
- Github::Markdown
- Github::Meta
- Github::MimeType
- Github::Normalizer
- Github::Orgs
- Github::Orgs::Members
- Github::Orgs::Teams
- Github::PageIterator
- Github::PageLinks
- Github::PagedRequest
- Github::Pagination
- Github::ParameterFilter
- Github::ParamsHash
- Github::PullRequests
- Github::PullRequests::Comments
- Github::RateLimit
- Github::Repos
- Github::Repos::Collaborators
- Github::Repos::Comments
- Github::Repos::Commits
- Github::Repos::Contents
- Github::Repos::Downloads
- Github::Repos::Forks
- Github::Repos::Hooks
- Github::Repos::Keys
- Github::Repos::Merging
- Github::Repos::PubSubHubbub
- Github::Repos::Statistics
- Github::Repos::Statuses
- Github::Request
- Github::Request::BasicAuth
- Github::Request::Jsonize
- Github::Request::OAuth2
- Github::Resource
- Github::Response
- Github::Response::Header
- Github::Response::Jsonize
- Github::Response::Mashify
- Github::Response::RaiseError
- Github::Response::Xmlize
- Github::ResponseWrapper
- Github::S3Uploader
- Github::Say
- Github::Scopes
- Github::Search
- Github::Users
- Github::Users::Emails
- Github::Users::Followers
- Github::Users::Keys
- Github::Utils
- Github::Utils::Url
- Github::VERSION
- Github::Validations
- Github::Validations::Format
- Github::Validations::Presence
- Github::Validations::Required
- Github::Validations::Token
- Hash

No matching classes.

# Github::Error::ServiceError

### Attributes

http_headers[R]

### Public Class Methods

errors() click to toggle source

    # File lib/github_api/error/service_error.rb, line 56
    def self.errors
      @errors ||= Hash[
        descendants.map { |klass| [klass.new({}).http_status_code, klass] }
      ]
    end

http_status_code(code) click to toggle source

    # File lib/github_api/error/service_error.rb, line 52
    def self.http_status_code(code)
      define_method(:http_status_code) { code }
    end

new(response) click to toggle source

    # File lib/github_api/error/service_error.rb, line 12
    def initialize(response)
      @http_headers = response[:response_headers]
      message = parse_response(response)
      super(message)
    end

### Public Instance Methods

decode_body(body) click to toggle source

    # File lib/github_api/error/service_error.rb, line 23
    def decode_body(body)
      if body.respond_to?(:to_str) && body.length >= 2
         decode body, :symbolize_keys => true
      else
        body
      end
    end

parse_body(body) click to toggle source

    # File lib/github_api/error/service_error.rb, line 31
    def parse_body(body)
      body = decode_body(body)

      return '' if body.nil? || body.empty?

      if body[:error]
        body[:error]
      elsif body[:errors]
        error = Array(body[:errors]).first
        if error.kind_of?(Hash)
          error[:message]
        else
          error
        end
      elsif body[:message]
        body[:message]
      else
        ''
      end
    end

parse_response(response) click to toggle source

    # File lib/github_api/error/service_error.rb, line 18
    def parse_response(response)
      body = parse_body(response[:body])
      "#{response[:method].to_s.upcase} #{response[:url].to_s}: #{response[:status]} #{body}"
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.