Exception: Buildkit::Error
- Inherits:
-
StandardError
- Object
- StandardError
- Buildkit::Error
- Defined in:
- lib/buildkit/error.rb
Overview
Custom error class for rescuing from all Buildkite errors
Direct Known Subclasses
Class Method Summary collapse
-
.from_response(response) ⇒ Buildkit::Error
Returns the appropriate Buildkit::Error subclass based on status and response message.
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.
34 35 36 37 |
# File 'lib/buildkit/error.rb', line 34 def initialize(response = nil) @response = response super() end |
Class Method Details
.from_response(response) ⇒ Buildkit::Error
Returns the appropriate Buildkit::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 |
# File 'lib/buildkit/error.rb', line 11 def self.from_response(response) status = response[:status].to_i if klass = case status when 400 then Buildkit::BadRequest when 401 then Buildkit::Unauthorized when 403 then Buildkit::Forbidden when 404 then Buildkit::NotFound when 405 then Buildkit::MethodNotAllowed when 406 then Buildkit::NotAcceptable when 409 then Buildkit::Conflict when 415 then Buildkit::UnsupportedMediaType when 422 then Buildkit::UnprocessableEntity when 400..499 then Buildkit::ClientError when 500 then Buildkit::InternalServerError when 501 then Buildkit::NotImplemented when 502 then Buildkit::BadGateway when 503 then Buildkit::ServiceUnavailable when 500..599 then Buildkit::ServerError end klass.new(response) end end |
Instance Method Details
#documentation_url ⇒ String
Documentation URL returned by the API for some errors
42 43 44 |
# File 'lib/buildkit/error.rb', line 42 def documentation_url data[:documentation_url] if data.is_a? Hash end |
#errors ⇒ Array<Hash>
Array of validation errors
48 49 50 51 52 53 54 |
# File 'lib/buildkit/error.rb', line 48 def errors if data&.is_a?(Hash) data[:errors] || [] else [] end end |