mejor soporte de errores

This commit is contained in:
f 2021-03-22 16:47:01 -03:00
parent 5f87540de7
commit 43430ca730

View file

@ -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