BadGateway, BadRequest, Conflict, Forbidden, InternalServerError, MethodNotAllowed, NotAcceptable, NotFound, NotImplemented, ServiceUnavailable, Unauthorized, UnavailableForLegalReasons, UnprocessableEntity, UnsupportedMediaType
Constant Summary collapse2
#response_headers, #response_message
Class Method Summary collapseA mapping of status codes and error types.
Add http status code method to error type.
Expose response payload as JSON object if possible.
Stores error message(s) returned in response body.
Create a ServiceError.
41 42 43 44 45 46 47 48 49 50
# File 'lib/github_api/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(create_message(response)) endClass 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_api/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_api/error/service_error.rb', line 17 def self.http_status_code(code) define_method(:http_status_code) { code } endInstance Method Details #data ⇒ Hash[Symbol]|String
Expose response payload as JSON object if possible
57 58 59
# File 'lib/github_api/error/service_error.rb', line 57 def data @data ||= decode_data(@body) end#error_messages ⇒ Array[Hash[Symbol]]
Stores error message(s) returned in response body
67 68 69 70 71
# File 'lib/github_api/error/service_error.rb', line 67 def error_messages @error_messages ||= begin data[:errors] ? data[:errors] : [data] end end
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4