module LifenFhir class Error < StandardError attr_accessor :response, :params def initialize(message: , response: nil, params: {}, client: "app", token: nil) self.response = response self.params = params @client = client @token = token super(message) end def context return {} if response.nil? { url: response.env.url.to_s, method: response.env.method.to_s, token: trucanted_token, payload_sent: filtered_params, trace_id: extracted_trace_id, payload_received: response.body, client: @client } end def raven_context { :extra => { lifen: context } } end private def extracted_trace_id response.headers.fetch("X-B3-Traceid") { "unknown" } end def trucanted_token if m = /^(.{24})(.*)$/.match(@token) "#{m[1]}#{"*" * m[2].length}" else @token end end def filtered_params filtered_params = params filtered_params[:payload] = "filtered" if filtered_params.is_a?(Hash) and filtered_params.has_key? :payload filtered_params end end end