diff options
author | Hubert Chathi <hubert@uhoreg.ca> | 2020-04-25 12:56:34 -0400 |
---|---|---|
committer | Hubert Chathi <hubert@uhoreg.ca> | 2020-04-25 12:56:34 -0400 |
commit | 63b8ef8988279be89bd08d8f5f1398f9e22c26db (patch) | |
tree | c3869bb1f247f200a7bf756810d5bc00c7675e2f | |
parent | documentation and type checking fixes/improvements (diff) |
pass through errors from hackney
-rw-r--r-- | lib/polyjuice/client.ex | 47 |
1 files changed, 25 insertions, 22 deletions
diff --git a/lib/polyjuice/client.ex b/lib/polyjuice/client.ex index aff224c..4d27da8 100644 --- a/lib/polyjuice/client.ex +++ b/lib/polyjuice/client.ex @@ -127,28 +127,31 @@ defmodule Polyjuice.Client do if auth_required and access_token == nil do {:error, :auth_required} else - # FIXME: handle errors - {:ok, status_code, resp_headers, body} = - :hackney.request( - method, - url, - if access_token do - [{"Authorization", "Bearer #{access_token}"} | headers] - else - headers - end, - body, - [:with_body] - ) - - Logger.debug("status code #{status_code}") - - Polyjuice.Client.Endpoint.Proto.transform_http_result( - endpoint, - status_code, - resp_headers, - body - ) + case :hackney.request( + method, + url, + if access_token do + [{"Authorization", "Bearer #{access_token}"} | headers] + else + headers + end, + body, + [:with_body] + ) do + {:ok, status_code, resp_headers, body} -> + Logger.debug("status code #{status_code}") + + Polyjuice.Client.Endpoint.Proto.transform_http_result( + endpoint, + status_code, + resp_headers, + body + ) + + err -> + # anything else is an error -- return as-is + err + end end end |