From 2f2b9ab1f458912e71fcaf6611d04fa8e2c22a1f Mon Sep 17 00:00:00 2001 From: Georg Gadinger Date: Tue, 28 Apr 2020 20:32:36 +0200 Subject: [PATCH] New Relic be like: *notices your errors* OwO what's this? --- app/controllers/ajax/answer_controller.rb | 3 ++- app/controllers/ajax/comment_controller.rb | 3 ++- app/controllers/ajax/friend_controller.rb | 6 ++++-- app/controllers/ajax/group_controller.rb | 18 ++++++++++++------ app/controllers/ajax/inbox_controller.rb | 9 ++++++--- app/controllers/ajax/moderation_controller.rb | 12 ++++++++---- app/controllers/ajax/question_controller.rb | 6 ++++-- app/controllers/ajax/smile_controller.rb | 12 ++++++++---- 8 files changed, 46 insertions(+), 23 deletions(-) diff --git a/app/controllers/ajax/answer_controller.rb b/app/controllers/ajax/answer_controller.rb index 247eecc7..05a7ba7e 100644 --- a/app/controllers/ajax/answer_controller.rb +++ b/app/controllers/ajax/answer_controller.rb @@ -40,7 +40,8 @@ class Ajax::AnswerController < AjaxController else current_user.answer question, params[:answer] end - rescue + rescue => e + NewRelic::Agent.notice_error(e) @response[:status] = :err @response[:message] = I18n.t('messages.error') return diff --git a/app/controllers/ajax/comment_controller.rb b/app/controllers/ajax/comment_controller.rb index 29132a52..283da8d7 100644 --- a/app/controllers/ajax/comment_controller.rb +++ b/app/controllers/ajax/comment_controller.rb @@ -7,7 +7,8 @@ class Ajax::CommentController < AjaxController begin current_user.comment(answer, params[:comment]) - rescue ActiveRecord::RecordInvalid + rescue ActiveRecord::RecordInvalid => e + NewRelic::Agent.notice_error(e) @response[:status] = :rec_inv @response[:message] = I18n.t('messages.comment.create.rec_inv') return diff --git a/app/controllers/ajax/friend_controller.rb b/app/controllers/ajax/friend_controller.rb index 30dac4d3..829ec769 100644 --- a/app/controllers/ajax/friend_controller.rb +++ b/app/controllers/ajax/friend_controller.rb @@ -6,7 +6,8 @@ class Ajax::FriendController < AjaxController begin current_user.follow target_user - rescue + rescue => e + NewRelic::Agent.notice_error(e) @response[:status] = :fail @response[:message] = I18n.t('messages.friend.create.fail') return @@ -24,7 +25,8 @@ class Ajax::FriendController < AjaxController begin current_user.unfollow target_user - rescue + rescue => e + NewRelic::Agent.notice_error(e) @response[:status] = :fail @response[:message] = I18n.t('messages.friend.destroy.fail') return diff --git a/app/controllers/ajax/group_controller.rb b/app/controllers/ajax/group_controller.rb index 06e8a3fb..8d364136 100644 --- a/app/controllers/ajax/group_controller.rb +++ b/app/controllers/ajax/group_controller.rb @@ -10,7 +10,8 @@ class Ajax::GroupController < AjaxController begin params.require :name - rescue ActionController::ParameterMissing + rescue ActionController::ParameterMissing => e + NewRelic::Agent.notice_error(e) @response[:status] = :toolong @response[:message] = I18n.t('messages.group.create.noname') return @@ -20,15 +21,18 @@ class Ajax::GroupController < AjaxController begin target_user = User.find_by_screen_name(params[:user]) group = Group.create! user: current_user, display_name: params[:name] - rescue ActiveRecord::RecordInvalid + rescue ActiveRecord::RecordInvalid => e + NewRelic::Agent.notice_error(e) @response[:status] = :toolong @response[:message] = I18n.t('messages.group.create.toolong') return - rescue ActiveRecord::RecordNotFound + rescue ActiveRecord::RecordNotFound => e + NewRelic::Agent.notice_error(e) @response[:status] = :notfound @response[:message] = I18n.t('messages.group.create.notfound') return - rescue ActiveRecord::RecordNotUnique + rescue ActiveRecord::RecordNotUnique => e + NewRelic::Agent.notice_error(e) @response[:status] = :exists @response[:message] = I18n.t('messages.group.create.exists') return @@ -53,7 +57,8 @@ class Ajax::GroupController < AjaxController begin Group.where(user: current_user, name: params[:group]).first.destroy! - rescue ActiveRecord::RecordNotFound + rescue ActiveRecord::RecordNotFound => e + NewRelic::Agent.notice_error(e) @response[:status] = :notfound @response[:message] = I18n.t('messages.group.destroy.notfound') return @@ -81,7 +86,8 @@ class Ajax::GroupController < AjaxController begin group = current_user.groups.find_by_name(params[:group]) - rescue ActiveRecord::RecordNotFound + rescue ActiveRecord::RecordNotFound => e + NewRelic::Agent.notice_error(e) @response[:status] = :notfound @response[:message] = I18n.t('messages.group.membership.notfound') return diff --git a/app/controllers/ajax/inbox_controller.rb b/app/controllers/ajax/inbox_controller.rb index 4a7ac797..0aa99cdc 100644 --- a/app/controllers/ajax/inbox_controller.rb +++ b/app/controllers/ajax/inbox_controller.rb @@ -33,7 +33,8 @@ class Ajax::InboxController < AjaxController begin inbox.remove - rescue + rescue => e + NewRelic::Agent.notice_error(e) @response[:status] = :err @response[:message] = I18n.t('messages.error') return @@ -47,7 +48,8 @@ class Ajax::InboxController < AjaxController def remove_all begin Inbox.where(user: current_user).each { |i| i.remove } - rescue + rescue => e + NewRelic::Agent.notice_error(e) @response[:status] = :err @response[:message] = I18n.t('messages.error') return @@ -64,7 +66,8 @@ class Ajax::InboxController < AjaxController @inbox = current_user.inboxes.joins(:question) .where(questions: { user_id: @target_user.id, author_is_anonymous: false }) @inbox.each { |i| i.remove } - rescue + rescue => e + NewRelic::Agent.notice_error(e) @response[:status] = :err @response[:message] = I18n.t('messages.error') return diff --git a/app/controllers/ajax/moderation_controller.rb b/app/controllers/ajax/moderation_controller.rb index bb606007..850c3564 100644 --- a/app/controllers/ajax/moderation_controller.rb +++ b/app/controllers/ajax/moderation_controller.rb @@ -7,7 +7,8 @@ class Ajax::ModerationController < AjaxController begin current_user.report_vote(report, params[:upvote]) - rescue + rescue => e + NewRelic::Agent.notice_error(e) @response[:status] = :fail @response[:message] = I18n.t('messages.moderation.vote.fail') return @@ -26,7 +27,8 @@ class Ajax::ModerationController < AjaxController begin current_user.report_unvote report - rescue + rescue => e + NewRelic::Agent.notice_error(e) @response[:status] = :fail @response[:message] = I18n.t('messages.moderation.destroy_vote.fail') return @@ -46,7 +48,8 @@ class Ajax::ModerationController < AjaxController begin report.deleted = true report.save - rescue + rescue => e + NewRelic::Agent.notice_error(e) @response[:status] = :fail @response[:message] = I18n.t('messages.moderation.destroy_report.fail') return @@ -66,7 +69,8 @@ class Ajax::ModerationController < AjaxController begin current_user.report_comment(report, params[:comment]) - rescue ActiveRecord::RecordInvalid + rescue ActiveRecord::RecordInvalid => e + NewRelic::Agent.notice_error(e) @response[:status] = :rec_inv @response[:message] = I18n.t('messages.moderation.create_comment.rec_inv') return diff --git a/app/controllers/ajax/question_controller.rb b/app/controllers/ajax/question_controller.rb index ffe0c636..acdc3109 100644 --- a/app/controllers/ajax/question_controller.rb +++ b/app/controllers/ajax/question_controller.rb @@ -31,7 +31,8 @@ class Ajax::QuestionController < AjaxController question = Question.create!(content: params[:question], author_is_anonymous: params[:anonymousQuestion], user: current_user) - rescue ActiveRecord::RecordInvalid + rescue ActiveRecord::RecordInvalid => e + NewRelic::Agent.notice_error(e) @response[:status] = :rec_inv @response[:message] = I18n.t('messages.question.create.rec_inv') return @@ -50,7 +51,8 @@ class Ajax::QuestionController < AjaxController begin current_user.groups.find_by_name!(params[:rcpt].sub 'grp:', '') QuestionWorker.perform_async params[:rcpt], current_user.id, question.id - rescue ActiveRecord::RecordNotFound + rescue ActiveRecord::RecordNotFound => e + NewRelic::Agent.notice_error(e) @response[:status] = :not_found @response[:message] = I18n.t('messages.question.create.not_found') return diff --git a/app/controllers/ajax/smile_controller.rb b/app/controllers/ajax/smile_controller.rb index bc486c9f..0e7ae9e2 100644 --- a/app/controllers/ajax/smile_controller.rb +++ b/app/controllers/ajax/smile_controller.rb @@ -6,7 +6,8 @@ class Ajax::SmileController < AjaxController begin current_user.smile answer - rescue + rescue => e + NewRelic::Agent.notice_error(e) @response[:status] = :fail @response[:message] = I18n.t('messages.smile.create.fail') return @@ -24,7 +25,8 @@ class Ajax::SmileController < AjaxController begin current_user.unsmile answer - rescue + rescue => e + NewRelic::Agent.notice_error(e) @response[:status] = :fail @response[:message] = I18n.t('messages.smile.destroy.fail') return @@ -42,7 +44,8 @@ class Ajax::SmileController < AjaxController begin current_user.smile_comment comment - rescue + rescue => e + NewRelic::Agent.notice_error(e) @response[:status] = :fail @response[:message] = I18n.t('messages.smile.create_comment.fail') return @@ -60,7 +63,8 @@ class Ajax::SmileController < AjaxController begin current_user.unsmile_comment comment - rescue + rescue => e + NewRelic::Agent.notice_error(e) @response[:status] = :fail @response[:message] = I18n.t('messages.smile.destroy_comment.fail') return