diff --git a/app/controllers/errors_controller.rb b/app/controllers/errors_controller.rb new file mode 100644 index 00000000..53e4aeb7 --- /dev/null +++ b/app/controllers/errors_controller.rb @@ -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 diff --git a/public/404.html b/app/views/errors/404.html similarity index 100% rename from public/404.html rename to app/views/errors/404.html diff --git a/public/422.html b/app/views/errors/422.html similarity index 100% rename from public/422.html rename to app/views/errors/422.html diff --git a/public/500.html b/app/views/errors/500.html similarity index 100% rename from public/500.html rename to app/views/errors/500.html diff --git a/config/application.rb b/config/application.rb index 8c9db35e..df3b9ee5 100644 --- a/config/application.rb +++ b/config/application.rb @@ -25,6 +25,8 @@ module DocuSeal config.i18n.available_locales = %i[en en-US en-GB es-ES fr-FR pt-PT de-DE] config.i18n.fallbacks = [:en] + config.exceptions_app = ->(env) { ErrorsController.action(:show).call(env) } + config.action_view.frozen_string_literal = true config.middleware.insert_before ActionDispatch::Static, Rack::Deflater