Exception: PagerDuty::Error
- Inherits:
-
StandardError
- Object
- StandardError
- PagerDuty::Error
- Defined in:
- lib/pager_duty/error.rb
Direct Known Subclasses
Class Method Summary collapse
Instance Method Summary collapse
-
#documentation_url ⇒ String
Documentation URL returned by the API for some errors.
-
#errors ⇒ Array<Hash>
Array of validation errors.
-
#initialize(response = nil) ⇒ Error
constructor
A new instance of Error.
Constructor Details
#initialize(response = nil) ⇒ Error
Returns a new instance of Error.
31 32 33 34 |
# File 'lib/pager_duty/error.rb', line 31 def initialize(response=nil) @response = response super() end |
Class Method Details
.from_response(response) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/pager_duty/error.rb', line 4 def self.from_response(response) status = response[:status].to_i body = response[:body].to_s headers = response[:response_headers] if klass = case status when 400 then PagerDuty::BadRequest when 401 then PagerDuty::Unauthorized when 402 then PagerDuty::AbilityMissing when 403 then PagerDuty::Forbidden when 404 then PagerDuty::NotFound when 406 then PagerDuty::NotAcceptable when 409 then PagerDuty::Conflict when 415 then PagerDuty::UnsupportedMediaType when 422 then PagerDuty::UnprocessableEntity when 429 then PagerDuty::UnprocessableEntity when 400..499 then PagerDuty::ClientError when 500 then PagerDuty::InternalServerError when 501 then PagerDuty::NotImplemented when 502 then PagerDuty::BadGateway when 503 then PagerDuty::ServiceUnavailable when 500..599 then PagerDuty::ServerError end klass.new(response) end end |
Instance Method Details
#documentation_url ⇒ String
Documentation URL returned by the API for some errors
39 40 41 |
# File 'lib/pager_duty/error.rb', line 39 def documentation_url data[:documentation_url] if data.is_a? Hash end |
#errors ⇒ Array<Hash>
Array of validation errors
45 46 47 48 49 50 51 |
# File 'lib/pager_duty/error.rb', line 45 def errors if data && data.is_a?(Hash) data[:errors] || [] else [] end end |