Exception: Bugsnag::Api::Error
- Inherits:
-
StandardError
- Object
- StandardError
- Bugsnag::Api::Error
- Defined in:
- lib/bugsnag/api/error.rb
Overview
Custom error class for rescuing from all Bugsnag API errors
Direct Known Subclasses
Class Method Summary collapse
-
.from_response(response) ⇒ Octokit::Error
Returns the appropriate Bugsnag::Api::Error subclass based on status and response message.
Instance Method Summary collapse
-
#initialize(response = nil) ⇒ Error
constructor
A new instance of Error.
Constructor Details
#initialize(response = nil) ⇒ Error
Returns a new instance of Error.
38 39 40 41 |
# File 'lib/bugsnag/api/error.rb', line 38 def initialize(response=nil) @response = response super() end |
Class Method Details
.from_response(response) ⇒ Octokit::Error
Returns the appropriate Bugsnag::Api::Error subclass based on status and response message
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/bugsnag/api/error.rb', line 11 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 Bugsnag::Api::BadRequest when 401 then Bugsnag::Api::Unauthorized when 403 then Bugsnag::Api::Forbidden when 404 then Bugsnag::Api::NotFound when 405 then Bugsnag::Api::MethodNotAllowed when 406 then Bugsnag::Api::NotAcceptable when 409 then Bugsnag::Api::Conflict when 415 then Bugsnag::Api::UnsupportedMediaType when 422 then Bugsnag::Api::UnprocessableEntity when 429 then Bugsnag::Api::RateLimitExceeded when 400..499 then Bugsnag::Api::ClientError when 500 then Bugsnag::Api::InternalServerError when 501 then Bugsnag::Api::NotImplemented when 502 then Bugsnag::Api::BadGateway when 503 then Bugsnag::Api::ServiceUnavailable when 500..599 then Bugsnag::Api::ServerError end klass.new(response) end end |