Merge pull request #9608 from tchak/fix-api-client
fix(api_client): fix some edge cases
This commit is contained in:
commit
5bf0d3ed54
1 changed files with 4 additions and 4 deletions
|
@ -7,7 +7,7 @@ class API::Client
|
||||||
response = case method
|
response = case method
|
||||||
when :get
|
when :get
|
||||||
Typhoeus.get(url,
|
Typhoeus.get(url,
|
||||||
headers: headers_with_authorization(headers, authorization_token),
|
headers: headers_with_authorization(headers, false, authorization_token),
|
||||||
params:,
|
params:,
|
||||||
timeout: TIMEOUT)
|
timeout: TIMEOUT)
|
||||||
when :post
|
when :post
|
||||||
|
@ -40,8 +40,8 @@ class API::Client
|
||||||
body = parse_body(response.body)
|
body = parse_body(response.body)
|
||||||
case body
|
case body
|
||||||
in Success(body)
|
in Success(body)
|
||||||
if !schema || schema.valid?(body)
|
if !schema || schema.valid?(body.deep_stringify_keys)
|
||||||
Success(OK[body.deep_symbolize_keys, response])
|
Success(OK[body, response])
|
||||||
else
|
else
|
||||||
Failure(Error[:schema, response.code, false, SchemaError.new(schema.validate(body))])
|
Failure(Error[:schema, response.code, false, SchemaError.new(schema.validate(body))])
|
||||||
end
|
end
|
||||||
|
@ -58,7 +58,7 @@ class API::Client
|
||||||
end
|
end
|
||||||
|
|
||||||
def parse_body(body)
|
def parse_body(body)
|
||||||
Success(JSON.parse(body))
|
Success(JSON.parse(body, symbolize_names: true))
|
||||||
rescue JSON::ParserError => error
|
rescue JSON::ParserError => error
|
||||||
Failure(error)
|
Failure(error)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue