Files
docuseal/app/controllers/errors_controller.rb
T

59 lines
1.7 KiB
Ruby
Raw Normal View History

2023-11-22 01:41:39 +02:00
# frozen_string_literal: true
class ErrorsController < ActionController::Base
ENTERPRISE_FEATURE_MESSAGE =
2024-01-04 15:28:46 +02:00
'This feature is available in Pro Edition: https://www.docuseal.co/pricing'
2023-11-22 01:41:39 +02:00
ENTERPRISE_PATHS = [
'/templates/html',
'/api/templates/html',
'/templates/pdf',
2023-12-22 16:36:15 +02:00
'/api/templates/pdf',
'/templates/doc',
'/api/templates/doc',
'/templates/docx',
'/api/templates/docx'
2023-11-22 01:41:39 +02:00
].freeze
2024-04-24 13:12:29 +03:00
SAFE_ERROR_MESSAGE_CLASSES = [
ActionDispatch::Http::Parameters::ParseError,
JSON::ParserError
].freeze
2023-11-22 01:41:39 +02:00
def show
2023-12-06 10:50:20 +02:00
if request.original_fullpath.in?(ENTERPRISE_PATHS) && error_status_code == 404
2023-11-22 01:41:39 +02:00
return render json: { status: 404, message: ENTERPRISE_FEATURE_MESSAGE }, status: :not_found
end
respond_to do |f|
f.json do
2024-03-10 15:54:44 +02:00
set_cors_headers
2024-04-24 13:12:29 +03:00
exception = request.env['action_dispatch.exception']
error = exception.message if exception.class.in?(SAFE_ERROR_MESSAGE_CLASSES)
render json: { status: error_status_code, error: }.compact, status: error_status_code
2023-11-22 01:41:39 +02:00
end
f.html { render error_status_code.to_s, status: error_status_code }
end
end
private
2024-03-10 15:54:44 +02:00
def set_cors_headers
headers['Access-Control-Allow-Origin'] = '*'
headers['Access-Control-Allow-Methods'] = 'POST, GET, PUT, PATCH, DELETE, OPTIONS'
headers['Access-Control-Allow-Headers'] = '*'
headers['Access-Control-Max-Age'] = '1728000'
headers['Access-Control-Allow-Credentials'] = true
end
2023-11-22 01:41:39 +02:00
def error_status_code
@error_status_code ||=
ActionDispatch::ExceptionWrapper.new(request.env,
request.env['action_dispatch.exception']).status_code
end
end