Class: Cubes::Middleware::RaiseError
- Inherits:
-
Faraday::Response::Middleware
- Object
- Faraday::Response::Middleware
- Cubes::Middleware::RaiseError
- Defined in:
- lib/cubes/middleware/raise_error.rb
Instance Method Summary collapse
-
#on_complete(env) ⇒ Object
Handle client errors.
Instance Method Details
#on_complete(env) ⇒ Object
Handle client errors
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/cubes/middleware/raise_error.rb', line 7 def on_complete(env) response = JSON.parse env.body if response.is_a?(Hash) && response['error'] == 'not_found' raise Cubes::Error::ResourceNotFound.new(response[:message]) end if env[:status] == 404 raise Cubes::Error::RouteNotFound.new('Route not found.') end end |