From 43430ca730aecf56af7b4370676a170aa26cd311 Mon Sep 17 00:00:00 2001 From: f Date: Mon, 22 Mar 2021 16:47:01 -0300 Subject: [PATCH] mejor soporte de errores --- app/jobs/backtrace_job.rb | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/app/jobs/backtrace_job.rb b/app/jobs/backtrace_job.rb index 4f0eb63..17755dc 100644 --- a/app/jobs/backtrace_job.rb +++ b/app/jobs/backtrace_job.rb @@ -4,6 +4,8 @@ class BacktraceJob < ApplicationJob class BacktraceException < RuntimeError; end + EMPTY_SOURCEMAP = { 'mappings' => '' }.freeze + queue_as :low_priority attr_reader :params, :site_id @@ -67,14 +69,18 @@ class BacktraceJob < ApplicationJob # @param [String] La URL del map # @return [Hash] def data(map) - return {} unless map.start_with? 'https://' + return EMPTY_SOURCEMAP unless map.start_with? 'https://' map += '.map' unless map.end_with? '.map' @data ||= {} + # TODO: Soportar ETags para la descarga, probablemente pasar a + # Faraday con caché para esto. @data[map] ||= FastJsonparser.parse(Rails.cache.fetch(map, expires_in: 12.hours) do Down.open(map).read end, symbolize_keys: false) + rescue Down::Error, FastJsonparser::Error + EMPTY_SOURCEMAP end # Asume que todos los sourcemaps comparten la misma URL, lo @@ -85,13 +91,8 @@ class BacktraceJob < ApplicationJob # # @return [SourceMap::Map] def sourcemap - @sourcemap ||= - begin - sources.map do |map| - SourceMap::Map.from_hash data(map) - rescue Down::Error, FastJsonparser::Error - SourceMap::Map.new - end.reduce(&:+) - end + @sourcemap ||= sources.map do |map| + SourceMap::Map.from_hash data(map) + end.reduce(&:+) end end