lib/tikkie/api/exception.rb in tikkie-api-0.2.2 vs lib/tikkie/api/exception.rb in tikkie-api-2.0.0
- old
+ new
@@ -1,22 +1,42 @@
# frozen_string_literal: true
module Tikkie
module Api
- # Tikkie base exception.
- class Exception < RuntimeError
+ # Generic Tikkie Exception.
+ class Exception < StandardError
end
- # Exception when the authentication fails.
- class AuthenticationException < Tikkie::Api::Exception
- attr_reader :response, :body
+ # Exception when an HTTP request fails.
+ class RequestError < Tikkie::Api::Exception
+ attr_accessor :response
def initialize(response)
@response = response
- @body = response.body
+ end
- message = "Authentication failure at Tikkie"
- super(message)
+ def errors
+ response.errors
+ end
+
+ def request_uri
+ response.request_uri
+ end
+
+ def http_code
+ response.http_code
+ end
+
+ def http_message
+ response.http_message
+ end
+
+ def messages
+ errors.map(&:message)
+ end
+
+ def to_s
+ "#{http_code} #{http_message}: #{messages.join(', ')}"
end
end
end
end