fix: ActiveRecord::RecordNotFound Couldn't find Channel::WebWidget (#6523)

* fix: resucue ActiveRecord::RecordNotFound for webwidget controller

* chore: add rails.log
This commit is contained in:
Vishnu Narayanan
2023-02-23 19:16:07 +05:30
committed by GitHub
parent 6407745571
commit 71f2b27728
2 changed files with 11 additions and 0 deletions

View File

@@ -18,6 +18,9 @@ class WidgetsController < ActionController::Base
def set_web_widget
@web_widget = ::Channel::WebWidget.find_by!(website_token: permitted_params[:website_token])
rescue ActiveRecord::RecordNotFound
Rails.logger.error('web widget does not exist')
render json: { error: 'web widget does not exist' }, status: :not_found
end
def set_token

View File

@@ -33,5 +33,13 @@ describe '/widget', type: :request do
expect(response).to have_http_status(:unauthorized)
expect(response.body).to include('Account is suspended')
end
it 'returns 404 if the webwidget is deleted' do
web_widget.delete
get widget_url(website_token: web_widget.website_token)
expect(response).to have_http_status(:not_found)
expect(response.body).to include('web widget does not exist')
end
end
end