enviar más información

This commit is contained in:
f 2020-12-07 15:27:24 -03:00
parent e53a560af0
commit baa7d58715
2 changed files with 8 additions and 10 deletions

View file

@ -3,8 +3,6 @@
module Api
module V1
# Recibe notificaciones desde Airbrake
#
# TODO: Autenticación
class NoticesController < BaseController
skip_before_action :verify_authenticity_token
@ -14,7 +12,7 @@ module Api
def create
if verify_api_key
BacktraceJob.perform_later site_id: params[:site_id],
errors: airbrake_params.map(&:permit!).map(&:to_h)
params: airbrake_params.to_h
end
render status: 201, json: { id: 1, url: root_url }
@ -25,7 +23,7 @@ module Api
# XXX: Por alguna razón Airbrake envía los datos con Content-Type:
# text/plain.
def airbrake_params
@airbrake_params ||= params.merge!(JSON.parse(request.raw_post) || {}).require(:errors)
@airbrake_params ||= params.merge!(FastJsonparser.parse(request.raw_post) || {}).permit!
end
def site

View file

@ -4,15 +4,15 @@
class BacktraceJob < ApplicationJob
queue_as :low_priority
attr_reader :errors, :site_id
attr_reader :params, :site_id
def perform(site_id:, errors:)
def perform(site_id:, params:)
@site_id = site_id
@errors = errors
@params = params
return if files.empty?
errors.each do |error|
params['errors'].each do |error|
error['backtrace'].each do |backtrace|
offset = SourceMap::Offset.new(backtrace['line'], backtrace['column'])
mapping = sourcemap.bsearch(offset)
@ -28,7 +28,7 @@ class BacktraceJob < ApplicationJob
begin
raise NoMethodError
rescue NoMethodError => e
ExceptionNotifier.notify_exception(e, data: { site: site.name, errors: errors })
ExceptionNotifier.notify_exception(e, data: { site: site.name, params: params })
end
end
@ -40,7 +40,7 @@ class BacktraceJob < ApplicationJob
# Obtiene todos los archivos del backtrace
def files
@files ||= errors.map { |x| x['backtrace'] }.flatten.map { |x| x['file'].split('@').last }.uniq.select { |x| x.start_with? site.url }
@files ||= params['errors'].map { |x| x['backtrace'] }.flatten.map { |x| x['file'].split('@').last }.uniq.select { |x| x.start_with? site.url }
end
# Asume que todos los sourcemaps comparten la misma URL, lo