mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-15 06:51:42 +00:00
mejor soporte de errores
This commit is contained in:
parent
5f87540de7
commit
43430ca730
1 changed files with 10 additions and 9 deletions
|
@ -4,6 +4,8 @@
|
||||||
class BacktraceJob < ApplicationJob
|
class BacktraceJob < ApplicationJob
|
||||||
class BacktraceException < RuntimeError; end
|
class BacktraceException < RuntimeError; end
|
||||||
|
|
||||||
|
EMPTY_SOURCEMAP = { 'mappings' => '' }.freeze
|
||||||
|
|
||||||
queue_as :low_priority
|
queue_as :low_priority
|
||||||
|
|
||||||
attr_reader :params, :site_id
|
attr_reader :params, :site_id
|
||||||
|
@ -67,14 +69,18 @@ class BacktraceJob < ApplicationJob
|
||||||
# @param [String] La URL del map
|
# @param [String] La URL del map
|
||||||
# @return [Hash]
|
# @return [Hash]
|
||||||
def data(map)
|
def data(map)
|
||||||
return {} unless map.start_with? 'https://'
|
return EMPTY_SOURCEMAP unless map.start_with? 'https://'
|
||||||
|
|
||||||
map += '.map' unless map.end_with? '.map'
|
map += '.map' unless map.end_with? '.map'
|
||||||
|
|
||||||
@data ||= {}
|
@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
|
@data[map] ||= FastJsonparser.parse(Rails.cache.fetch(map, expires_in: 12.hours) do
|
||||||
Down.open(map).read
|
Down.open(map).read
|
||||||
end, symbolize_keys: false)
|
end, symbolize_keys: false)
|
||||||
|
rescue Down::Error, FastJsonparser::Error
|
||||||
|
EMPTY_SOURCEMAP
|
||||||
end
|
end
|
||||||
|
|
||||||
# Asume que todos los sourcemaps comparten la misma URL, lo
|
# Asume que todos los sourcemaps comparten la misma URL, lo
|
||||||
|
@ -85,13 +91,8 @@ class BacktraceJob < ApplicationJob
|
||||||
#
|
#
|
||||||
# @return [SourceMap::Map]
|
# @return [SourceMap::Map]
|
||||||
def sourcemap
|
def sourcemap
|
||||||
@sourcemap ||=
|
@sourcemap ||= sources.map do |map|
|
||||||
begin
|
SourceMap::Map.from_hash data(map)
|
||||||
sources.map do |map|
|
end.reduce(&:+)
|
||||||
SourceMap::Map.from_hash data(map)
|
|
||||||
rescue Down::Error, FastJsonparser::Error
|
|
||||||
SourceMap::Map.new
|
|
||||||
end.reduce(&:+)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue