Class: Dropmark::Error::RaiseError
- Inherits:
-
Faraday::Response::Middleware
- Object
- Faraday::Response::Middleware
- Dropmark::Error::RaiseError
- Defined in:
- lib/dropmark/error.rb
Instance Method Summary collapse
Instance Method Details
#on_complete(env) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/dropmark/error.rb', line 15 def on_complete(env) return if (status = env[:status]) < 400 # Ignore any non-error response codes = parse(env[:body]) case status when 400 raise Dropmark::Error::BadRequest, when 403 raise Dropmark::Error::Forbidden, when 404 raise Dropmark::Error::NotFound, else raise Dropmark::Error::ServerError, # Treat any other errors as 500 end end |
#parse(body) ⇒ Object
9 10 11 12 13 |
# File 'lib/dropmark/error.rb', line 9 def parse(body) if body = MultiJson.load(body, :symbolize_keys => true) body[:message] if body.has_key?(:message) end end |