module Lifen class AppAuthenticatedClient < Client def post(url, params = {}) response = faraday_client.post do |req| req.url url req.headers['secret_key'] = secret_key req.headers['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 private def secret_key Lifen.configuration.secret_key end end end