4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/lifen/app_authenticated_client.rb', line 4
def post(url, params = {})
response = faraday_client.post do |req|
req.url url
req.['secret_key'] = secret_key
req.['Content-Type'] = "application/json"
req.body = JSON.generate(params)
end
if response.status == 500
json = JSON.parse response.body
trace_id = json.fetch("X-B3-TraceId", "unknown")
raise Error, "Error 500, Internal server error (trace ID: #{trace_id})"
end
raise Error, "Error 400" if response.status == 400
raise Error, "Error 404, Page not found" if response.status == 404
raise InvalidSecretTokenError if response.status == 401
raise UserAlreadyExistingError if response.status == 403
json = JSON.parse response.body
json
end
|