From baa7d5871551c09ffe6c1ba18a33f5fef4315e96 Mon Sep 17 00:00:00 2001 From: f Date: Mon, 7 Dec 2020 15:27:24 -0300 Subject: [PATCH] =?UTF-8?q?enviar=20m=C3=A1s=20informaci=C3=B3n?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/v1/notices_controller.rb | 6 ++---- app/jobs/backtrace_job.rb | 12 ++++++------ 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/app/controllers/api/v1/notices_controller.rb b/app/controllers/api/v1/notices_controller.rb index c3e9659..bd2bcaa 100644 --- a/app/controllers/api/v1/notices_controller.rb +++ b/app/controllers/api/v1/notices_controller.rb @@ -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 diff --git a/app/jobs/backtrace_job.rb b/app/jobs/backtrace_job.rb index 6f2425e..a7192fd 100644 --- a/app/jobs/backtrace_job.rb +++ b/app/jobs/backtrace_job.rb @@ -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