Exception: Github::Error::ServiceError
- Inherits:
-
GithubError
- Object
- StandardError
- GithubError
- Github::Error::ServiceError
- Defined in:
- lib/github_api2/error/service_error.rb
Direct Known Subclasses
BadGateway, BadRequest, Conflict, Forbidden, InternalServerError, MethodNotAllowed, NotAcceptable, NotFound, NotImplemented, ServiceUnavailable, Unauthorized, UnavailableForLegalReasons, UnprocessableEntity, UnsupportedMediaType
Constant Summary collapse
- MIN_BODY_LENGTH =
2
Instance Attribute Summary
Attributes inherited from GithubError
#response_headers, #response_message
Class Method Summary collapse
-
.error_mapping ⇒ Hash[Integer, Object]
A mapping of status codes and error types.
-
.http_status_code(code) ⇒ Object
Add http status code method to error type.
Instance Method Summary collapse
-
#data ⇒ Hash[Symbol]|String
Expose response payload as JSON object if possible.
-
#error_messages ⇒ Array[Hash[Symbol]]
Stores error message(s) returned in response body.
-
#initialize(response) ⇒ ServiceError
constructor
Create a ServiceError.
Methods inherited from GithubError
Constructor Details
#initialize(response) ⇒ ServiceError
Create a ServiceError
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/github_api2/error/service_error.rb', line 41 def initialize(response) @headers = response[:response_headers] @body = response[:body] @status = response[:status] @response_headers = @headers @response_message = @body super((response)) end |
Class Method Details
.error_mapping ⇒ Hash[Integer, Object]
A mapping of status codes and error types
26 27 28 29 30 31 32 |
# File 'lib/github_api2/error/service_error.rb', line 26 def self.error_mapping @error_mapping ||= Hash[ descendants.map do |klass| [klass.new({}).http_status_code, klass] end ] end |
.http_status_code(code) ⇒ Object
Add http status code method to error type
17 18 19 |
# File 'lib/github_api2/error/service_error.rb', line 17 def self.http_status_code(code) define_method(:http_status_code) { code } end |
Instance Method Details
#data ⇒ Hash[Symbol]|String
Expose response payload as JSON object if possible
57 58 59 |
# File 'lib/github_api2/error/service_error.rb', line 57 def data @data ||= decode_data(@body) end |