lib/ezid/responses/response.rb in ezid-client-1.8.0 vs lib/ezid/responses/response.rb in ezid-client-1.9.0.rc1

- old
+ new

@@ -12,9 +12,22 @@ SUCCESS = "success".freeze # Error response status ERROR = "error".freeze + def initialize(http_response) + super + + unless __getobj__.code =~ /2\d\d/ + raise Error, "HTTP response error: %s %s" % + [ __getobj__.code, __getobj__.message ] + end + + unless status_line =~ /^(#{SUCCESS}|#{ERROR}): / + raise UnexpectedResponseError, __getobj__.body + end + end + # The response status -- "success" or "error" # @return [String] the status def status @status ||= status_line.split(/: /) end