Exception: TurbaKit::Error
- Inherits:
-
StandardError
- Object
- StandardError
- TurbaKit::Error
- Defined in:
- lib/turba_kit/error.rb
Direct Known Subclasses
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(body, status) ⇒ Error
constructor
A new instance of Error.
Constructor Details
#initialize(body, status) ⇒ Error
Returns a new instance of Error.
25 26 27 28 29 30 31 32 33 |
# File 'lib/turba_kit/error.rb', line 25 def initialize(body, status) = { status: status, error: body['error'] } super(Oj.dump(, mode: :compat)) raise self end |
Class Method Details
.from_response(body, status) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/turba_kit/error.rb', line 3 def self.from_response(body, status) if klass = case status.to_i when 400 then TurbaKit::BadRequest when 401 then TurbaKit::Unauthorized when 403 then TurbaKit::Forbidden when 404 then TurbaKit::NotFound when 405 then TurbaKit::MethodNotAllowed when 406 then TurbaKit::NotAcceptable when 409 then TurbaKit::Conflict when 415 then TurbaKit::UnsupportedMediaType when 422 then TurbaKit::UnprocessableEntity when 400..499 then TurbaKit::ClientError when 500 then TurbaKit::InternalServerError when 501 then TurbaKit::NotImplemented when 502 then TurbaKit::BadGateway when 503 then TurbaKit::ServiceUnavailable when 500..599 then TurbaKit::ServerError end klass.new(body, status) end end |