Exception: PagerDuty::Error

Inherits:
StandardError
  • Object
show all
Defined in:
lib/pager_duty/error.rb

Direct Known Subclasses

ClientError, ServerError

Class Method Summary collapse

Instance Method Summary collapse

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(build_error_message)
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_urlString

Documentation URL returned by the API for some errors

Returns:

  • (String)


39
40
41
# File 'lib/pager_duty/error.rb', line 39

def documentation_url
  data[:documentation_url] if data.is_a? Hash
end

#errorsArray<Hash>

Array of validation errors

Returns:

  • (Array<Hash>)

    Error info



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