From 74d07c876efa7daa24015348d9f52e97a2e7e74f Mon Sep 17 00:00:00 2001 From: Sojan Jose Date: Fri, 18 Sep 2020 18:50:53 +0530 Subject: [PATCH] chore: Fix RestClient::GatewayTimeout, label_list of NilClass (#1243) --- app/controllers/api/v1/widget/labels_controller.rb | 12 ++++++++---- app/jobs/contact_avatar_job.rb | 2 +- lib/webhooks/trigger.rb | 4 ++-- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/app/controllers/api/v1/widget/labels_controller.rb b/app/controllers/api/v1/widget/labels_controller.rb index e8e409244..c6435da4b 100644 --- a/app/controllers/api/v1/widget/labels_controller.rb +++ b/app/controllers/api/v1/widget/labels_controller.rb @@ -1,14 +1,18 @@ class Api::V1::Widget::LabelsController < Api::V1::Widget::BaseController def create - conversation.label_list.add(permitted_params[:label]) - conversation.save! + if conversation.present? + conversation.label_list.add(permitted_params[:label]) + conversation.save! + end head :no_content end def destroy - conversation.label_list.remove(permitted_params[:id]) - conversation.save! + if conversation.present? + conversation.label_list.remove(permitted_params[:id]) + conversation.save! + end head :no_content end diff --git a/app/jobs/contact_avatar_job.rb b/app/jobs/contact_avatar_job.rb index e1de371fd..f381b63f2 100644 --- a/app/jobs/contact_avatar_job.rb +++ b/app/jobs/contact_avatar_job.rb @@ -5,6 +5,6 @@ class ContactAvatarJob < ApplicationJob avatar_resource = LocalResource.new(avatar_url) contact.avatar.attach(io: avatar_resource.file, filename: avatar_resource.tmp_filename, content_type: avatar_resource.encoding) rescue Errno::ETIMEDOUT, Errno::ECONNREFUSED, SocketError, NoMethodError => e - Rails.logger.info "invalid url #{avatar_url} : #{e.message}" + Rails.logger.info "Exception: invalid avatar url #{avatar_url} : #{e.message}" end end diff --git a/lib/webhooks/trigger.rb b/lib/webhooks/trigger.rb index f3fe055dc..5475b75f7 100644 --- a/lib/webhooks/trigger.rb +++ b/lib/webhooks/trigger.rb @@ -1,8 +1,8 @@ class Webhooks::Trigger def self.execute(url, payload) RestClient.post(url, payload.to_json, { content_type: :json, accept: :json }) - rescue RestClient::NotFound => e - Rails.logger.info "invalid url #{url} : #{e.message}" + rescue RestClient::NotFound, RestClient::GatewayTimeout, SocketError => e + Rails.logger.info "Exception: invalid webhook url #{url} : #{e.message}" rescue StandardError => e Raven.capture_exception(e) end