lib/preservation/client/versioned_api_service.rb in preservation-client-5.2.0 vs lib/preservation/client/versioned_api_service.rb in preservation-client-5.3.0
- old
+ new
@@ -93,11 +93,22 @@
"got #{e.response[:status]} from Preservation at #{req_url}: #{e.response[:body]}"
raise NotFoundError, errmsg
rescue Faraday::Error => e
errmsg = "Preservation::Client.#{caller_locations.first.label} " \
"got #{e.response[:status]} from Preservation at #{req_url}: #{e.response[:body]}"
- exception_class = e.response[:status] == 423 ? LockedError : UnexpectedResponseError
- raise exception_class, errmsg
+ raise http_exception_class(e.response[:status]), errmsg
+ end
+
+ # @param status_code [Integer] the HTTP status code to translate to an exception class
+ def http_exception_class(status_code)
+ case status_code
+ when 423
+ LockedError
+ when 409
+ ConflictError
+ else
+ UnexpectedResponseError
+ end
end
end
end
end