add custom exceptions handling controller

This commit is contained in:
Pete Matsyburka
2023-11-22 01:41:39 +02:00
parent f2c6bb1c3d
commit 542a443fb8
5 changed files with 37 additions and 0 deletions
+35
View File
@@ -0,0 +1,35 @@
# frozen_string_literal: true
class ErrorsController < ActionController::Base
ENTERPRISE_FEATURE_MESSAGE =
'This feature is available in Enterprise Edition: https://www.docuseal.co/pricing'
ENTERPRISE_PATHS = [
'/templates/html',
'/api/templates/html',
'/templates/pdf',
'/api/templates/pdf'
].freeze
def show
if request.original_fullpath.in?(ENTERPRISE_PATHS)
return render json: { status: 404, message: ENTERPRISE_FEATURE_MESSAGE }, status: :not_found
end
respond_to do |f|
f.json do
render json: { status: error_status_code }, status: error_status_code
end
f.html { render error_status_code.to_s, status: error_status_code }
end
end
private
def error_status_code
@error_status_code ||=
ActionDispatch::ExceptionWrapper.new(request.env,
request.env['action_dispatch.exception']).status_code
end
end