From ad2d3d07feec7dda608703271d53b63652c6bbae Mon Sep 17 00:00:00 2001 From: Shivam Mishra Date: Thu, 22 Aug 2024 19:24:55 +0530 Subject: [PATCH] fix: handle nil event --- .../api/v1/accounts/integrations/hooks_controller.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/controllers/api/v1/accounts/integrations/hooks_controller.rb b/app/controllers/api/v1/accounts/integrations/hooks_controller.rb index 13bb2738b..087a9b78d 100644 --- a/app/controllers/api/v1/accounts/integrations/hooks_controller.rb +++ b/app/controllers/api/v1/accounts/integrations/hooks_controller.rb @@ -12,7 +12,12 @@ class Api::V1::Accounts::Integrations::HooksController < Api::V1::Accounts::Base def process_event response = @hook.process_event(params[:event]) - if response[:error] + + # for cases like an invalid event, or when conversation does not have enough messages + # for a label suggestion, the response is nil + if response.nil? + render json: { message: nil } + elsif response[:error] render json: { error: response[:error] }, status: :unprocessable_entity else render json: { message: response[:message] }