Class: Response::RaisePocketError

Inherits:
Middleware
  • Object
show all
Defined in:
lib/faraday/raise_pocket_error.rb

Overview

HTTP Status X-Error-Code X-Error 400 138 Missing consumer key. 403 152 Invalid consumer key. 400 181 Invalid redirect uri. 400 182 Missing code. 400 185 Code not found. 403 158 User rejected code. 403 159 Already used code. 50X 199 Pocket server issue.

Constant Summary collapse

CLIENT_ERRORS_STATUSES =
400...600

Instance Method Summary collapse

Instance Method Details

#on_complete(env) ⇒ Object



16
17
18
19
20
21
22
23
24
25
# File 'lib/faraday/raise_pocket_error.rb', line 16

def on_complete(env)
  case env[:status]
  when 404
    raise Faraday::Error::ResourceNotFound, response_values(env)
  when 400...403
    raise Pocket::Error, env[:response_headers]["X-Error"]
  when CLIENT_ERRORS_STATUSES
    raise Faraday::Error::ClientError, response_values(env)
  end
end

#response_values(env) ⇒ Object



27
28
29
# File 'lib/faraday/raise_pocket_error.rb', line 27

def response_values(env)
  {status: env[:status], headers: env[:response_headers], body: env[:body]}
end