Class: Base::RaiseError

Inherits:
Faraday::Response::Middleware
  • Object
show all
Defined in:
lib/base/endpoint.rb

Overview

Middleware to raise error on 422 and 401

Instance Method Summary collapse

Instance Method Details

#on_complete(env) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/base/endpoint.rb', line 10

def on_complete(env)
  case env[:status]
  when 422
    raise InvalidRequest, JSON.parse(env.body)
  when 401
    raise Unauthorized
  end
end