lib/hyper_resource/modules/http.rb in hyperresource-0.1.2 vs lib/hyper_resource/modules/http.rb in hyperresource-0.1.3

- old
+ new

@@ -1,10 +1,9 @@ require 'faraday' require 'uri' require 'json' - module HyperResource::Modules::HTTP ## Loads and returns the resource pointed to by +href+. The returned ## resource will be blessed into its "proper" class, if ## +self.class.namespace != nil+. @@ -29,11 +28,22 @@ end private def finish_up - self.response_body = JSON.parse(self.response.body) - self.init_from_response_body! - self.blessed + status = self.response.status + if status / 100 == 2 + self.response_body = JSON.parse(self.response.body) + self.init_from_response_body! + self.blessed + elsif status / 100 == 3 + ## TODO redirect logic? + elsif status / 100 == 4 + raise HyperResource::ClientError, status.to_s + elsif status / 100 == 5 + raise HyperResource::ServerError, status.to_s + else ## 1xx? really? + raise HyperResource::Exception, "Got status #{status}, wtf?" + end end end