module RSolr::Error::SolrContext
def parse_solr_error_response body
def parse_solr_error_response body begin # Default JSON response, try to parse and retrieve error message if response[:headers] && response[:headers]["content-type"].start_with?("application/json") begin parsed_body = JSON.parse(body) info = parsed_body && parsed_body["error"] && parsed_body["error"]["msg"] rescue JSON::ParserError end end return info if info # legacy analysis, I think trying to handle wt=ruby responses without # a full parse? if body =~ /<pre>/ info = body.scan(/<pre>(.*)<\/pre>/mi)[0] elsif body =~ /'msg'=>/ info = body.scan(/'msg'=>(.*)/)[0] end info = info.join if info.respond_to? :join info ||= body # body might not contain <pre> or msg elements partial = info.to_s.split("\n")[0..10] partial.join("\n").gsub(">", ">").gsub("<", "<") rescue nil end end
def to_s
def to_s m = "#{super.to_s}" if response m << " - #{response[:status]} #{Http::STATUS_CODES[response[:status].to_i]}" details = parse_solr_error_response response[:body] m << "\nError: #{details}\n" if details end p = "\nURI: #{clean_uri(request[:uri]).to_s}" p << "\nRequest Headers: #{request[:headers].inspect}" if request[:headers] p << "\nRequest Data: #{request[:data].inspect}" if request[:data] p << "\n" p << "\nBacktrace: " + self.backtrace[0..10].join("\n") m << p m end