diff --git a/.rubocop.yml b/.rubocop.yml index 47d210b1b..f61de8e17 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -316,6 +316,7 @@ Metrics/ClassLength: - 'packages/forest_admin_agent/lib/forest_admin_agent/routes/action/actions.rb' - 'packages/forest_admin_agent/lib/forest_admin_agent/services/smart_action_checker.rb' - 'packages/forest_admin_agent/lib/forest_admin_agent/routes/resources/related/update_related.rb' + - 'packages/forest_admin_agent/lib/forest_admin_agent/routes/resources/update_field.rb' - 'packages/forest_admin_agent/lib/forest_admin_agent/utils/schema/frontend_validation_utils.rb' - 'packages/forest_admin_agent/lib/forest_admin_agent/utils/query_string_parser.rb' - 'packages/forest_admin_datasource_active_record/lib/forest_admin_datasource_active_record/utils/query.rb' diff --git a/packages/forest_admin_agent/lib/forest_admin_agent.rb b/packages/forest_admin_agent/lib/forest_admin_agent.rb index be8270393..7e3ef30a4 100644 --- a/packages/forest_admin_agent/lib/forest_admin_agent.rb +++ b/packages/forest_admin_agent/lib/forest_admin_agent.rb @@ -1,5 +1,5 @@ require_relative 'forest_admin_agent/version' -require_relative 'forest_admin_agent/http/Exceptions/business_error' +require 'forest_admin_datasource_toolkit' require 'zeitwerk' loader = Zeitwerk::Loader.for_gem @@ -8,6 +8,6 @@ loader.setup module ForestAdminAgent - class Error < StandardError; end + class Error < ForestAdminDatasourceToolkit::Exceptions::BusinessError; end # Your code goes here... end diff --git a/packages/forest_admin_agent/lib/forest_admin_agent/auth/auth_manager.rb b/packages/forest_admin_agent/lib/forest_admin_agent/auth/auth_manager.rb index f331bdd43..158f2e320 100644 --- a/packages/forest_admin_agent/lib/forest_admin_agent/auth/auth_manager.rb +++ b/packages/forest_admin_agent/lib/forest_admin_agent/auth/auth_manager.rb @@ -15,7 +15,7 @@ def start(rendering_id) def verify_code_and_generate_token(params) unless params['state'] - raise ForestAdminAgent::Http::Exceptions::BadRequestError, + raise ForestAdminDatasourceToolkit::Exceptions::BadRequestError, ForestAdminAgent::Utils::ErrorMessages::INVALID_STATE_MISSING end @@ -40,7 +40,7 @@ def verify_code_and_generate_token(params) def get_rendering_id_from_state(state) state = JSON.parse(state.tr("'", '"').gsub('=>', ':')) unless state.key? 'renderingId' - raise ForestAdminAgent::Http::Exceptions::BadRequestError.new( + raise ForestAdminDatasourceToolkit::Exceptions::BadRequestError.new( ForestAdminAgent::Utils::ErrorMessages::INVALID_STATE_RENDERING_ID, details: { state: state } ) @@ -49,7 +49,7 @@ def get_rendering_id_from_state(state) begin Integer(state['renderingId']) rescue ArgumentError - raise ForestAdminAgent::Http::Exceptions::ValidationError.new( + raise ForestAdminDatasourceToolkit::Exceptions::ValidationError.new( ForestAdminAgent::Utils::ErrorMessages::INVALID_RENDERING_ID, details: { renderingId: state['renderingId'] } ) diff --git a/packages/forest_admin_agent/lib/forest_admin_agent/http/Exceptions/business_error.rb b/packages/forest_admin_agent/lib/forest_admin_agent/http/Exceptions/business_error.rb deleted file mode 100644 index 10d9268d3..000000000 --- a/packages/forest_admin_agent/lib/forest_admin_agent/http/Exceptions/business_error.rb +++ /dev/null @@ -1,101 +0,0 @@ -module ForestAdminAgent - module Http - module Exceptions - # Parent class for all business errors - # This is the base class that all specific error types inherit from - class BusinessError < StandardError - attr_reader :details, :cause - - def initialize(message = nil, details: {}, cause: nil) - super(message) - @details = details || {} - @cause = cause - end - - # Returns the name of the error class - def name - self.class.name.split('::').last - end - end - - # ==================== - # Specific error types - # ==================== - - class BadRequestError < BusinessError - def initialize(message = 'Bad request', details: {}) - super - end - end - - class ValidationError < BadRequestError - def initialize(message = 'Validation failed', details: {}) - super - end - end - - class UnauthorizedError < BusinessError - def initialize(message = 'Unauthorized', details: {}) - super - end - end - - class AuthenticationOpenIdClient < UnauthorizedError - def initialize(message = 'Authentication failed with OpenID Client', details: {}) - super - end - end - - class ForbiddenError < BusinessError - def initialize(message = 'Forbidden', details: {}) - super - end - end - - class NotFoundError < BusinessError - def initialize(message, details: {}) - super - end - end - - class ConflictError < BusinessError - def initialize(message = 'Conflict', details: {}) - super - end - end - - class UnprocessableError < BusinessError - def initialize(message = 'Unprocessable entity', details: {}) - super - end - end - - class TooManyRequestsError < BusinessError - attr_reader :retry_after - - def initialize(message, retry_after, details: {}) - super(message, details: details) - @retry_after = retry_after - end - end - - class InternalServerError < BusinessError - def initialize(message = 'Internal server error', details: {}, cause: nil) - super - end - end - - class BadGatewayError < BusinessError - def initialize(message = 'Bad gateway error', details: {}, cause: nil) - super - end - end - - class ServiceUnavailableError < BusinessError - def initialize(message = 'Service unavailable error', details: {}, cause: nil) - super - end - end - end - end -end diff --git a/packages/forest_admin_agent/lib/forest_admin_agent/http/Exceptions/http_exception.rb b/packages/forest_admin_agent/lib/forest_admin_agent/http/Exceptions/http_exception.rb index 2925fcafe..7210dc06b 100644 --- a/packages/forest_admin_agent/lib/forest_admin_agent/http/Exceptions/http_exception.rb +++ b/packages/forest_admin_agent/lib/forest_admin_agent/http/Exceptions/http_exception.rb @@ -1,5 +1,3 @@ -require_relative 'business_error' - module ForestAdminAgent module Http module Exceptions diff --git a/packages/forest_admin_agent/lib/forest_admin_agent/http/error_translator.rb b/packages/forest_admin_agent/lib/forest_admin_agent/http/error_translator.rb index 622321c2f..ee1234563 100644 --- a/packages/forest_admin_agent/lib/forest_admin_agent/http/error_translator.rb +++ b/packages/forest_admin_agent/lib/forest_admin_agent/http/error_translator.rb @@ -1,4 +1,3 @@ -require_relative 'Exceptions/business_error' require_relative 'Exceptions/http_exception' module ForestAdminAgent @@ -33,35 +32,30 @@ def self.translate(error) # @param error [Exception] The error to get status for # @return [Integer] The HTTP status code def self.get_error_status(error) - if defined?(ForestAdminDatasourceToolkit::Exceptions::ValidationError) && - of_type?(error, ForestAdminDatasourceToolkit::Exceptions::ValidationError) - return 400 - end - error.status if error.respond_to?(:status) && error.status case error - when Exceptions::ValidationError, Exceptions::BadRequestError + when ForestAdminDatasourceToolkit::Exceptions::ValidationError, ForestAdminDatasourceToolkit::Exceptions::BadRequestError 400 - when Exceptions::UnauthorizedError + when ForestAdminDatasourceToolkit::Exceptions::UnauthorizedError 401 - when Exceptions::ForbiddenError + when ForestAdminDatasourceToolkit::Exceptions::ForbiddenError 403 - when Exceptions::NotFoundError + when ForestAdminDatasourceToolkit::Exceptions::NotFoundError 404 - when Exceptions::ConflictError + when ForestAdminDatasourceToolkit::Exceptions::ConflictError 409 - when Exceptions::UnprocessableError + when ForestAdminDatasourceToolkit::Exceptions::UnprocessableError 422 - when Exceptions::TooManyRequestsError + when ForestAdminDatasourceToolkit::Exceptions::TooManyRequestsError 429 - when Exceptions::InternalServerError + when ForestAdminDatasourceToolkit::Exceptions::InternalServerError 500 - when Exceptions::BadGatewayError + when ForestAdminDatasourceToolkit::Exceptions::BadGatewayError 502 - when Exceptions::ServiceUnavailableError + when ForestAdminDatasourceToolkit::Exceptions::ServiceUnavailableError 503 - when Exceptions::BusinessError + when ForestAdminDatasourceToolkit::Exceptions::BusinessError # default BusinessError → 422 (Unprocessable Entity) 422 else @@ -82,7 +76,7 @@ def self.get_error_message(error) end is_known_error = error.is_a?(Exceptions::HttpException) || - error.is_a?(Exceptions::BusinessError) || + error.is_a?(ForestAdminDatasourceToolkit::Exceptions::BusinessError) || (defined?(ForestAdminDatasourceToolkit::Exceptions::ForestException) && error.is_a?(ForestAdminDatasourceToolkit::Exceptions::ForestException)) @@ -95,7 +89,7 @@ def self.get_error_message(error) # @param error [Exception] The error to get data from # @return [Hash, nil] The error metadata or nil def self.get_error_data(error) - return error.details if error.is_a?(Exceptions::BusinessError) && + return error.details if error.is_a?(ForestAdminDatasourceToolkit::Exceptions::BusinessError) && error.respond_to?(:details) && !error.details.empty? @@ -107,9 +101,9 @@ def self.get_error_data(error) # @return [Proc, nil] A proc that generates custom headers def self.get_custom_headers(error) case error - when Exceptions::NotFoundError + when ForestAdminDatasourceToolkit::Exceptions::NotFoundError { 'x-error-type' => 'object-not-found' } - when Exceptions::TooManyRequestsError + when ForestAdminDatasourceToolkit::Exceptions::TooManyRequestsError { 'Retry-After' => error.retry_after.to_s } end end diff --git a/packages/forest_admin_agent/lib/forest_admin_agent/http/forest_admin_api_requester.rb b/packages/forest_admin_agent/lib/forest_admin_agent/http/forest_admin_api_requester.rb index 522476743..f0d5e99ea 100644 --- a/packages/forest_admin_agent/lib/forest_admin_agent/http/forest_admin_api_requester.rb +++ b/packages/forest_admin_agent/lib/forest_admin_agent/http/forest_admin_api_requester.rb @@ -3,7 +3,6 @@ module ForestAdminAgent module Http class ForestAdminApiRequester - include ForestAdminAgent::Http::Exceptions include ForestAdminDatasourceToolkit::Exceptions def initialize @@ -30,7 +29,7 @@ def post(url, params = nil) def handle_response_error(error) # Re-raise if it's already a BusinessError - raise error if error.is_a?(ForestAdminAgent::Http::Exceptions::BusinessError) + raise error if error.is_a?(BusinessError) raise error if error.is_a?(ForestException) if error.response[:message]&.include?('certificate') diff --git a/packages/forest_admin_agent/lib/forest_admin_agent/routes/action/actions.rb b/packages/forest_admin_agent/lib/forest_admin_agent/routes/action/actions.rb index 8bf543d6c..a37cf21f9 100644 --- a/packages/forest_admin_agent/lib/forest_admin_agent/routes/action/actions.rb +++ b/packages/forest_admin_agent/lib/forest_admin_agent/routes/action/actions.rb @@ -111,7 +111,8 @@ def handle_hook_request(args = {}) private def middleware_custom_action_approval_request_data(args) - raise Http::Exceptions::UnprocessableError if args.dig(:params, :data, :attributes, :requester_id) + raise ForestAdminDatasourceToolkit::Exceptions::UnprocessableError if args.dig(:params, :data, :attributes, + :requester_id) if (signed_request = args.dig(:params, :data, :attributes, :signed_approval_request)) args[:params][:data][:attributes][:signed_approval_request] = decode_signed_approval_request(signed_request) diff --git a/packages/forest_admin_agent/lib/forest_admin_agent/routes/query_handler.rb b/packages/forest_admin_agent/lib/forest_admin_agent/routes/query_handler.rb index 6358a1e8b..f5b16a0b8 100644 --- a/packages/forest_admin_agent/lib/forest_admin_agent/routes/query_handler.rb +++ b/packages/forest_admin_agent/lib/forest_admin_agent/routes/query_handler.rb @@ -30,7 +30,8 @@ def parse_query_segment(collection, args, permissions, caller) return unless args[:params][:segmentQuery] unless args[:params][:connectionName] - raise ForestAdminAgent::Http::Exceptions::UnprocessableError, 'Missing native query connection attribute' + raise ForestAdminDatasourceToolkit::Exceptions::UnprocessableError, + 'Missing native query connection attribute' end QueryValidator.valid?(args[:params][:segmentQuery]) diff --git a/packages/forest_admin_agent/lib/forest_admin_agent/routes/resources/native_query.rb b/packages/forest_admin_agent/lib/forest_admin_agent/routes/resources/native_query.rb index 01a094f96..340ecf55f 100644 --- a/packages/forest_admin_agent/lib/forest_admin_agent/routes/resources/native_query.rb +++ b/packages/forest_admin_agent/lib/forest_admin_agent/routes/resources/native_query.rb @@ -7,7 +7,6 @@ module Resources class NativeQuery < AbstractAuthenticatedRoute include ForestAdminAgent::Builder include ForestAdminAgent::Utils - include ForestAdminAgent::Http::Exceptions include ForestAdminDatasourceToolkit::Exceptions include ForestAdminDatasourceToolkit::Components::Charts include ForestAdminAgent::Routes::QueryHandler @@ -31,7 +30,8 @@ def handle_request(args = {}) QueryValidator.valid?(query) unless args[:params][:connectionName] - raise ForestAdminAgent::Http::Exceptions::UnprocessableError, 'Missing native query connection attribute' + raise ForestAdminDatasourceToolkit::Exceptions::UnprocessableError, + 'Missing native query connection attribute' end @permissions.can_chart?(args[:params]) @@ -62,7 +62,7 @@ def type=(type) end def raise_error(result, key_names) - raise BadRequestError, + raise ForestAdminDatasourceToolkit::Exceptions::BadRequestError, "The result columns must be named #{key_names} instead of '#{result.keys.join("', '")}'" end diff --git a/packages/forest_admin_agent/lib/forest_admin_agent/routes/resources/show.rb b/packages/forest_admin_agent/lib/forest_admin_agent/routes/resources/show.rb index 528a205d6..46585b44f 100644 --- a/packages/forest_admin_agent/lib/forest_admin_agent/routes/resources/show.rb +++ b/packages/forest_admin_agent/lib/forest_admin_agent/routes/resources/show.rb @@ -27,7 +27,10 @@ def handle_request(args = {}) records = @collection.list(@caller, filter, projection) - raise Http::Exceptions::NotFoundError, 'Record does not exists' unless records.size.positive? + unless records.size.positive? + raise ForestAdminDatasourceToolkit::Exceptions::NotFoundError, + 'Record does not exists' + end { name: args[:params]['collection_name'], diff --git a/packages/forest_admin_agent/lib/forest_admin_agent/routes/resources/update_field.rb b/packages/forest_admin_agent/lib/forest_admin_agent/routes/resources/update_field.rb index ade8184e8..754f2b1a3 100644 --- a/packages/forest_admin_agent/lib/forest_admin_agent/routes/resources/update_field.rb +++ b/packages/forest_admin_agent/lib/forest_admin_agent/routes/resources/update_field.rb @@ -68,23 +68,26 @@ def handle_request(args = {}) def parse_index(index_param) index = Integer(index_param) - raise Http::Exceptions::ValidationError, 'Index must be non-negative' if index.negative? + if index.negative? + raise ForestAdminDatasourceToolkit::Exceptions::ValidationError, + 'Index must be non-negative' + end index rescue ArgumentError - raise Http::Exceptions::ValidationError, "Invalid index: #{index_param}" + raise ForestAdminDatasourceToolkit::Exceptions::ValidationError, "Invalid index: #{index_param}" end def validate_array_field!(field_schema, field_name) FieldValidator.validate(@collection, field_name) return if field_schema.column_type.is_a?(Array) - raise Http::Exceptions::ValidationError, + raise ForestAdminDatasourceToolkit::Exceptions::ValidationError, "Field '#{field_name}' is not an array (type: #{field_schema.column_type})" rescue ForestAdminDatasourceToolkit::Exceptions::ValidationError => e - raise Http::Exceptions::NotFoundError, e.message if e.message.include?('not found') + raise ForestAdminDatasourceToolkit::Exceptions::NotFoundError, e.message if e.message.include?('not found') - raise Http::Exceptions::ValidationError, e.message + raise ForestAdminDatasourceToolkit::Exceptions::ValidationError, e.message end def fetch_record(primary_key_values) @@ -95,20 +98,20 @@ def fetch_record(primary_key_values) ) records = @collection.list(@caller, filter, ProjectionFactory.all(@collection)) - raise Http::Exceptions::NotFoundError, 'Record not found' unless records&.any? + raise ForestAdminDatasourceToolkit::Exceptions::NotFoundError, 'Record not found' unless records&.any? records[0] end def validate_array_value!(array, field_name, array_index) unless array.is_a?(Array) - raise Http::Exceptions::UnprocessableError, + raise ForestAdminDatasourceToolkit::Exceptions::UnprocessableError, "Field '#{field_name}' value is not an array (got: #{array.class})" end return unless array_index >= array.length - raise Http::Exceptions::ValidationError, + raise ForestAdminDatasourceToolkit::Exceptions::ValidationError, "Index #{array_index} out of bounds for array of length #{array.length}" end @@ -128,7 +131,8 @@ def coerce_value(value, column_type) begin return Float(value) rescue ArgumentError - raise Http::Exceptions::ValidationError, "Cannot coerce '#{value}' to Number - wrong type" + raise ForestAdminDatasourceToolkit::Exceptions::ValidationError, + "Cannot coerce '#{value}' to Number - wrong type" end end diff --git a/packages/forest_admin_agent/lib/forest_admin_agent/routes/security/authentication.rb b/packages/forest_admin_agent/lib/forest_admin_agent/routes/security/authentication.rb index c436d01df..e04689334 100644 --- a/packages/forest_admin_agent/lib/forest_admin_agent/routes/security/authentication.rb +++ b/packages/forest_admin_agent/lib/forest_admin_agent/routes/security/authentication.rb @@ -5,7 +5,7 @@ module Routes module Security class Authentication < AbstractRoute include ForestAdminAgent::Builder - include ForestAdminAgent::Http::Exceptions + include ForestAdminDatasourceToolkit::Exceptions def setup_routes add_route( diff --git a/packages/forest_admin_agent/lib/forest_admin_agent/services/ip_whitelist.rb b/packages/forest_admin_agent/lib/forest_admin_agent/services/ip_whitelist.rb index 828aab407..2cf8a5f5c 100644 --- a/packages/forest_admin_agent/lib/forest_admin_agent/services/ip_whitelist.rb +++ b/packages/forest_admin_agent/lib/forest_admin_agent/services/ip_whitelist.rb @@ -40,7 +40,7 @@ def ip_matches_rule?(ip, rule) when RULE_MATCH_SUBNET ip_match_subnet?(ip, rule['range']) else - raise ForestAdminAgent::Http::Exceptions::InternalServerError, 'Invalid rule type' + raise ForestAdminDatasourceToolkit::Exceptions::InternalServerError, 'Invalid rule type' end end @@ -93,7 +93,7 @@ def fetch_rules status: response.status, response: response.body }) - raise ForestAdminAgent::Http::Exceptions::InternalServerError, + raise ForestAdminDatasourceToolkit::Exceptions::InternalServerError, ForestAdminAgent::Utils::ErrorMessages::UNEXPECTED end @@ -105,7 +105,7 @@ def fetch_rules status: response.status, response: response.body }) - raise ForestAdminAgent::Http::Exceptions::InternalServerError, + raise ForestAdminDatasourceToolkit::Exceptions::InternalServerError, ForestAdminAgent::Utils::ErrorMessages::UNEXPECTED end @@ -119,7 +119,7 @@ def fetch_rules status: response&.status, response: response&.body }) - raise ForestAdminAgent::Http::Exceptions::InternalServerError, + raise ForestAdminDatasourceToolkit::Exceptions::InternalServerError, ForestAdminAgent::Utils::ErrorMessages::UNEXPECTED end end diff --git a/packages/forest_admin_agent/lib/forest_admin_agent/services/smart_action_checker.rb b/packages/forest_admin_agent/lib/forest_admin_agent/services/smart_action_checker.rb index 21c21a4ac..d359fb31b 100644 --- a/packages/forest_admin_agent/lib/forest_admin_agent/services/smart_action_checker.rb +++ b/packages/forest_admin_agent/lib/forest_admin_agent/services/smart_action_checker.rb @@ -1,6 +1,6 @@ module ForestAdminAgent module Services - include ForestAdminAgent::Http::Exceptions + include ForestAdminDatasourceToolkit::Exceptions class CustomActionTriggerForbiddenError < ForbiddenError def initialize(message = 'Custom action trigger forbidden', details: {}) diff --git a/packages/forest_admin_agent/lib/forest_admin_agent/utils/caller_parser.rb b/packages/forest_admin_agent/lib/forest_admin_agent/utils/caller_parser.rb index 679c01fc5..e37a56ed7 100644 --- a/packages/forest_admin_agent/lib/forest_admin_agent/utils/caller_parser.rb +++ b/packages/forest_admin_agent/lib/forest_admin_agent/utils/caller_parser.rb @@ -5,7 +5,6 @@ module ForestAdminAgent module Utils class CallerParser - include ForestAdminAgent::Http::Exceptions include ForestAdminDatasourceToolkit::Exceptions def initialize(args) @@ -30,7 +29,7 @@ def parse def validate_headers return if @args.dig(:headers, 'HTTP_AUTHORIZATION') - raise Http::Exceptions::UnauthorizedError, 'You must be logged in to access at this resource.' + raise UnauthorizedError, 'You must be logged in to access at this resource.' end def extract_timezone diff --git a/packages/forest_admin_agent/lib/forest_admin_agent/utils/condition_tree_parser.rb b/packages/forest_admin_agent/lib/forest_admin_agent/utils/condition_tree_parser.rb index 5bde4d47a..d2e4ef7b3 100644 --- a/packages/forest_admin_agent/lib/forest_admin_agent/utils/condition_tree_parser.rb +++ b/packages/forest_admin_agent/lib/forest_admin_agent/utils/condition_tree_parser.rb @@ -4,7 +4,7 @@ module ForestAdminAgent module Utils class ConditionTreeParser - include ForestAdminAgent::Http::Exceptions + include ForestAdminDatasourceToolkit::Exceptions include ForestAdminDatasourceToolkit::Utils include ForestAdminDatasourceToolkit::Components::Query::ConditionTree include ForestAdminDatasourceToolkit::Components::Query::ConditionTree::Nodes diff --git a/packages/forest_admin_agent/lib/forest_admin_agent/utils/query_validator.rb b/packages/forest_admin_agent/lib/forest_admin_agent/utils/query_validator.rb index 7ef3b48fd..c5f141d8c 100644 --- a/packages/forest_admin_agent/lib/forest_admin_agent/utils/query_validator.rb +++ b/packages/forest_admin_agent/lib/forest_admin_agent/utils/query_validator.rb @@ -8,7 +8,7 @@ module QueryValidator def self.valid?(query) query = query.strip - raise Http::Exceptions::BadRequestError, 'Query cannot be empty.' if query.empty? + raise ForestAdminDatasourceToolkit::Exceptions::BadRequestError, 'Query cannot be empty.' if query.empty? sanitized_query = remove_content_inside_strings(query) check_select_only(sanitized_query) @@ -26,23 +26,27 @@ class << self def check_select_only(query) return if query.strip.upcase.start_with?('SELECT') - raise Http::Exceptions::BadRequestError, 'Only SELECT queries are allowed.' + raise ForestAdminDatasourceToolkit::Exceptions::BadRequestError, 'Only SELECT queries are allowed.' end def check_semicolon_placement(query) semicolon_count = query.scan(';').size - raise Http::Exceptions::BadRequestError, 'Only one query is allowed.' if semicolon_count > 1 + if semicolon_count > 1 + raise ForestAdminDatasourceToolkit::Exceptions::BadRequestError, + 'Only one query is allowed.' + end return if semicolon_count != 1 || query.strip[-1] == ';' - raise Http::Exceptions::BadRequestError, 'Semicolon must only appear as the last character in the query.' + raise ForestAdminDatasourceToolkit::Exceptions::BadRequestError, + 'Semicolon must only appear as the last character in the query.' end def check_forbidden_keywords(query) FORBIDDEN_KEYWORDS.each do |keyword| next unless /\b#{Regexp.escape(keyword)}\b/i.match?(query) - raise Http::Exceptions::BadRequestError.new( + raise ForestAdminDatasourceToolkit::Exceptions::BadRequestError.new( "The query contains forbidden keyword: #{keyword}.", details: { forbidden_keyword: keyword } ) @@ -55,7 +59,7 @@ def check_unbalanced_parentheses(query) return if open_count == close_count - raise Http::Exceptions::BadRequestError.new( + raise ForestAdminDatasourceToolkit::Exceptions::BadRequestError.new( 'The query contains unbalanced parentheses.', details: { open_count: open_count, close_count: close_count } ) @@ -65,7 +69,8 @@ def check_sql_injection_patterns(query) INJECTION_PATTERNS.each do |pattern| next unless pattern.match?(query) - raise Http::Exceptions::BadRequestError, 'The query contains a potential SQL injection pattern.' + raise ForestAdminDatasourceToolkit::Exceptions::BadRequestError, + 'The query contains a potential SQL injection pattern.' end end diff --git a/packages/forest_admin_agent/lib/forest_admin_agent/utils/schema/generator_action_field_widget.rb b/packages/forest_admin_agent/lib/forest_admin_agent/utils/schema/generator_action_field_widget.rb index cfb2a5d84..07b4d46c8 100644 --- a/packages/forest_admin_agent/lib/forest_admin_agent/utils/schema/generator_action_field_widget.rb +++ b/packages/forest_admin_agent/lib/forest_admin_agent/utils/schema/generator_action_field_widget.rb @@ -2,7 +2,7 @@ module ForestAdminAgent module Utils module Schema class GeneratorActionFieldWidget - include ForestAdminAgent::Http::Exceptions + include ForestAdminDatasourceToolkit::Exceptions def self.build_widget_options(field) return if !ActionFields.widget?(field) || %w[Collection Enum EnumList].include?(field.type) diff --git a/packages/forest_admin_agent/spec/lib/forest_admin_agent/builder/agent_factory_spec.rb b/packages/forest_admin_agent/spec/lib/forest_admin_agent/builder/agent_factory_spec.rb index 0e59476c7..d36541e9c 100644 --- a/packages/forest_admin_agent/spec/lib/forest_admin_agent/builder/agent_factory_spec.rb +++ b/packages/forest_admin_agent/spec/lib/forest_admin_agent/builder/agent_factory_spec.rb @@ -103,7 +103,7 @@ module Builder allow(Facades::Container).to receive(:cache).with(:is_production).and_return(true) allow(File).to receive(:exist?).with('/path/to/schema.json').and_return(false) - expect { instance.send_schema }.to raise_error(ForestAdminAgent::Http::Exceptions::InternalServerError) + expect { instance.send_schema }.to raise_error(ForestAdminDatasourceToolkit::Exceptions::InternalServerError) end it 'loads schema from file in production mode' do diff --git a/packages/forest_admin_agent/spec/lib/forest_admin_agent/http/error_translator_spec.rb b/packages/forest_admin_agent/spec/lib/forest_admin_agent/http/error_translator_spec.rb index 22c8a20d4..bfff75541 100644 --- a/packages/forest_admin_agent/spec/lib/forest_admin_agent/http/error_translator_spec.rb +++ b/packages/forest_admin_agent/spec/lib/forest_admin_agent/http/error_translator_spec.rb @@ -107,7 +107,7 @@ module Http context 'when error is a BusinessError' do let(:business_error) do - ForestAdminAgent::Http::Exceptions::BadRequestError.new('Bad request error') + ForestAdminDatasourceToolkit::Exceptions::BadRequestError.new('Bad request error') end it 'returns the business error message' do @@ -132,7 +132,7 @@ module Http context 'when error is a BadRequestError' do let(:bad_request_error) do - ForestAdminAgent::Http::Exceptions::BadRequestError.new('Bad request') + ForestAdminDatasourceToolkit::Exceptions::BadRequestError.new('Bad request') end it 'returns 400' do @@ -143,7 +143,7 @@ module Http context 'when error is a ForbiddenError' do let(:forbidden_error) do - ForestAdminAgent::Http::Exceptions::ForbiddenError.new('Forbidden') + ForestAdminDatasourceToolkit::Exceptions::ForbiddenError.new('Forbidden') end it 'returns 403' do @@ -154,7 +154,7 @@ module Http context 'when error is a NotFoundError' do let(:not_found_error) do - ForestAdminAgent::Http::Exceptions::NotFoundError.new('Not found') + ForestAdminDatasourceToolkit::Exceptions::NotFoundError.new('Not found') end it 'returns 404' do @@ -165,7 +165,7 @@ module Http context 'when error is an UnprocessableError' do let(:unprocessable_error) do - ForestAdminAgent::Http::Exceptions::UnprocessableError.new('Unprocessable') + ForestAdminDatasourceToolkit::Exceptions::UnprocessableError.new('Unprocessable') end it 'returns 422' do diff --git a/packages/forest_admin_agent/spec/lib/forest_admin_agent/http/forest_admin_api_requester_spec.rb b/packages/forest_admin_agent/spec/lib/forest_admin_agent/http/forest_admin_api_requester_spec.rb index 6ed704f2b..ca086b753 100644 --- a/packages/forest_admin_agent/spec/lib/forest_admin_agent/http/forest_admin_api_requester_spec.rb +++ b/packages/forest_admin_agent/spec/lib/forest_admin_agent/http/forest_admin_api_requester_spec.rb @@ -42,7 +42,7 @@ module Http expect do forest_admin_api_requester.handle_response_error(Faraday::ConnectionFailed.new('test', { message: 'certificate' })) end.to raise_error( - ForestAdminAgent::Http::Exceptions::InternalServerError, + ForestAdminDatasourceToolkit::Exceptions::InternalServerError, 'ForestAdmin server TLS certificate cannot be verified. Please check that your system time is set properly.' ) end @@ -51,7 +51,7 @@ module Http expect do forest_admin_api_requester.handle_response_error(Faraday::ConnectionFailed.new('test', { status: 0 })) end.to raise_error( - ForestAdminAgent::Http::Exceptions::BadGatewayError, + ForestAdminDatasourceToolkit::Exceptions::BadGatewayError, 'Failed to reach ForestAdmin server. Are you online?' ) end @@ -60,7 +60,7 @@ module Http expect do forest_admin_api_requester.handle_response_error(Faraday::ConnectionFailed.new('test', { status: 502 })) end.to raise_error( - ForestAdminAgent::Http::Exceptions::BadGatewayError, + ForestAdminDatasourceToolkit::Exceptions::BadGatewayError, 'Failed to reach ForestAdmin server. Are you online?' ) end @@ -69,7 +69,7 @@ module Http expect do forest_admin_api_requester.handle_response_error(Faraday::ConnectionFailed.new('test', { status: 404 })) end.to raise_error( - ForestAdminAgent::Http::Exceptions::NotFoundError, + ForestAdminDatasourceToolkit::Exceptions::NotFoundError, 'ForestAdmin server failed to find the project related to the envSecret you configured. Can you check that you copied it properly in the Forest initialization?' ) end @@ -78,7 +78,7 @@ module Http expect do forest_admin_api_requester.handle_response_error(Faraday::ConnectionFailed.new('test', { status: 503 })) end.to raise_error( - ForestAdminAgent::Http::Exceptions::ServiceUnavailableError, + ForestAdminDatasourceToolkit::Exceptions::ServiceUnavailableError, 'Forest is in maintenance for a few minutes. We are upgrading your experience in the forest. We just need a few more minutes to get it right.' ) end @@ -87,7 +87,7 @@ module Http expect do forest_admin_api_requester.handle_response_error(Faraday::ConnectionFailed.new('test', { status: 500 })) end.to raise_error( - ForestAdminAgent::Http::Exceptions::InternalServerError, + ForestAdminDatasourceToolkit::Exceptions::InternalServerError, 'An unexpected error occurred while contacting the ForestAdmin server. Please contact support@forestadmin.com for further investigations.' ) end diff --git a/packages/forest_admin_agent/spec/lib/forest_admin_agent/routes/query_handler_spec.rb b/packages/forest_admin_agent/spec/lib/forest_admin_agent/routes/query_handler_spec.rb index 24958738a..d093518a5 100644 --- a/packages/forest_admin_agent/spec/lib/forest_admin_agent/routes/query_handler_spec.rb +++ b/packages/forest_admin_agent/spec/lib/forest_admin_agent/routes/query_handler_spec.rb @@ -5,7 +5,7 @@ module Routes include ForestAdminDatasourceToolkit include ForestAdminDatasourceToolkit::Schema include ForestAdminDatasourceToolkit::Components::Query::ConditionTree - include ForestAdminAgent::Http::Exceptions + include ForestAdminDatasourceToolkit::Exceptions describe QueryHandler do include_context 'with caller' diff --git a/packages/forest_admin_agent/spec/lib/forest_admin_agent/routes/resources/action/actions_spec.rb b/packages/forest_admin_agent/spec/lib/forest_admin_agent/routes/resources/action/actions_spec.rb index 8434393f1..98d1998b0 100644 --- a/packages/forest_admin_agent/spec/lib/forest_admin_agent/routes/resources/action/actions_spec.rb +++ b/packages/forest_admin_agent/spec/lib/forest_admin_agent/routes/resources/action/actions_spec.rb @@ -12,6 +12,7 @@ module Action include ForestAdminDatasourceToolkit::Components::Query include ForestAdminDatasourceToolkit::Components::Query::ConditionTree include ForestAdminDatasourceToolkit::Components::Query::ConditionTree::Nodes + include ForestAdminDatasourceToolkit::Exceptions describe Actions do include_context 'with caller' @@ -106,7 +107,7 @@ module Action args[:params][:data][:attributes][:requester_id] = 'requester_id' allow(@action_collection).to receive(:execute) - expect { action.handle_request(args) }.to raise_error(Http::Exceptions::UnprocessableError) + expect { action.handle_request(args) }.to raise_error(UnprocessableError) end end diff --git a/packages/forest_admin_agent/spec/lib/forest_admin_agent/routes/resources/list_spec.rb b/packages/forest_admin_agent/spec/lib/forest_admin_agent/routes/resources/list_spec.rb index cb4661d62..846e777a5 100644 --- a/packages/forest_admin_agent/spec/lib/forest_admin_agent/routes/resources/list_spec.rb +++ b/packages/forest_admin_agent/spec/lib/forest_admin_agent/routes/resources/list_spec.rb @@ -140,7 +140,7 @@ module Resources it 'throws an error when the filter operator is not allowed' do args[:params][:filters] = JSON.generate({ field: 'id', operator: 'shorter_than', value: 7 }) - expect { list.handle_request(args) }.to raise_error(ForestException, "The given operator 'shorter_than' is not supported by the column: 'id'. The column is not filterable") + expect { list.handle_request(args) }.to raise_error(ValidationError, "The given operator 'shorter_than' is not supported by the column: 'id'. The column is not filterable") end end end diff --git a/packages/forest_admin_agent/spec/lib/forest_admin_agent/routes/resources/native_query_spec.rb b/packages/forest_admin_agent/spec/lib/forest_admin_agent/routes/resources/native_query_spec.rb index e71fdec60..253be38e3 100644 --- a/packages/forest_admin_agent/spec/lib/forest_admin_agent/routes/resources/native_query_spec.rb +++ b/packages/forest_admin_agent/spec/lib/forest_admin_agent/routes/resources/native_query_spec.rb @@ -64,7 +64,7 @@ module Resources expect do native_query.handle_request(args) end.to raise_error( - ForestAdminAgent::Http::Exceptions::UnprocessableError, 'Missing native query connection attribute' + ForestAdminDatasourceToolkit::Exceptions::UnprocessableError, 'Missing native query connection attribute' ) end @@ -140,7 +140,7 @@ module Resources allow(datasource).to receive(:execute_native_query).and_return([{ foo: 10 }]) expect { native_query.handle_request(args) }.to raise_error( - ForestAdminAgent::Http::Exceptions::BadRequestError, + ForestAdminDatasourceToolkit::Exceptions::BadRequestError, "The result columns must be named 'value' instead of 'foo'" ) end @@ -184,7 +184,7 @@ module Resources allow(datasource).to receive(:execute_native_query).and_return([{ foo: 10 }]) expect { native_query.handle_request(args) }.to raise_error( - ForestAdminAgent::Http::Exceptions::BadRequestError, + ForestAdminDatasourceToolkit::Exceptions::BadRequestError, "The result columns must be named 'value' instead of 'foo'" ) end @@ -228,7 +228,7 @@ module Resources allow(datasource).to receive(:execute_native_query).and_return([{ foo: 10 }]) expect { native_query.handle_request(args) }.to raise_error( - ForestAdminAgent::Http::Exceptions::BadRequestError, + ForestAdminDatasourceToolkit::Exceptions::BadRequestError, "The result columns must be named 'key', 'value' instead of 'foo'" ) end @@ -285,7 +285,7 @@ module Resources ) expect { native_query.handle_request(args) }.to raise_error( - ForestAdminAgent::Http::Exceptions::BadRequestError, + ForestAdminDatasourceToolkit::Exceptions::BadRequestError, "The result columns must be named 'key', 'value' instead of 'value', 'foo'" ) end @@ -348,7 +348,7 @@ module Resources ) expect { native_query.handle_request(args) }.to raise_error( - ForestAdminAgent::Http::Exceptions::BadRequestError, + ForestAdminDatasourceToolkit::Exceptions::BadRequestError, "The result columns must be named 'key', 'value' instead of 'value', 'foo'" ) end diff --git a/packages/forest_admin_agent/spec/lib/forest_admin_agent/routes/resources/update_field_spec.rb b/packages/forest_admin_agent/spec/lib/forest_admin_agent/routes/resources/update_field_spec.rb index 1a226d49e..686586066 100644 --- a/packages/forest_admin_agent/spec/lib/forest_admin_agent/routes/resources/update_field_spec.rb +++ b/packages/forest_admin_agent/spec/lib/forest_admin_agent/routes/resources/update_field_spec.rb @@ -7,6 +7,7 @@ module Resources include ForestAdminDatasourceToolkit include ForestAdminDatasourceToolkit::Components::Query::ConditionTree include ForestAdminDatasourceToolkit::Schema + include ForestAdminDatasourceToolkit::Exceptions describe UpdateField do include_context 'with caller' @@ -200,12 +201,12 @@ def update(_caller, _filter, _patch) book = { 'id' => 1, 'tags' => ['test'] } @collection.list_responses = [[book]] allow(permissions).to receive(:can?).with(:edit, anything) - .and_raise(Http::Exceptions::ForbiddenError.new('Permission denied')) + .and_raise(ForbiddenError.new('Permission denied')) end it 'raises ForbiddenError' do expect { update_field.handle_request(args) } - .to raise_error(Http::Exceptions::ForbiddenError) + .to raise_error(ForbiddenError) end end @@ -216,7 +217,7 @@ def update(_caller, _filter, _patch) it 'raises NotFoundError' do expect { update_field.handle_request(args_with_invalid_field) } - .to raise_error(Http::Exceptions::NotFoundError, /not found/) + .to raise_error(NotFoundError, /not found/) end end @@ -227,7 +228,7 @@ def update(_caller, _filter, _patch) it 'raises ValidationError' do expect { update_field.handle_request(args_with_non_array_field) } - .to raise_error(Http::Exceptions::ValidationError, /not an array/) + .to raise_error(ValidationError, /not an array/) end end @@ -238,7 +239,7 @@ def update(_caller, _filter, _patch) it 'raises NotFoundError' do expect { update_field.handle_request(args) } - .to raise_error(Http::Exceptions::NotFoundError, /not found/) + .to raise_error(NotFoundError, /not found/) end end @@ -254,7 +255,7 @@ def update(_caller, _filter, _patch) it 'raises ValidationError' do expect { update_field.handle_request(args_with_large_index) } - .to raise_error(Http::Exceptions::ValidationError, /out of bounds/) + .to raise_error(ValidationError, /out of bounds/) end end @@ -265,7 +266,7 @@ def update(_caller, _filter, _patch) it 'raises ValidationError' do expect { update_field.handle_request(args_with_negative_index) } - .to raise_error(Http::Exceptions::ValidationError, /non-negative/) + .to raise_error(ValidationError, /non-negative/) end end @@ -276,7 +277,7 @@ def update(_caller, _filter, _patch) it 'raises ValidationError' do expect { update_field.handle_request(args_with_invalid_index) } - .to raise_error(Http::Exceptions::ValidationError, /Invalid index/) + .to raise_error(ValidationError, /Invalid index/) end end @@ -288,7 +289,7 @@ def update(_caller, _filter, _patch) it 'raises UnprocessableError' do expect { update_field.handle_request(args) } - .to raise_error(Http::Exceptions::UnprocessableError, /not an array/) + .to raise_error(ForestAdminDatasourceToolkit::Exceptions::UnprocessableError, /not an array/) end end @@ -337,7 +338,7 @@ def update(_caller, _filter, _patch) it 'raises ValidationError' do expect { update_field.handle_request(args_with_invalid_number) } - .to raise_error(Http::Exceptions::ValidationError, /wrong type/) + .to raise_error(ValidationError, /wrong type/) end end end diff --git a/packages/forest_admin_agent/spec/lib/forest_admin_agent/routes/security/authentication_spec.rb b/packages/forest_admin_agent/spec/lib/forest_admin_agent/routes/security/authentication_spec.rb index 82b5a2378..92da75e24 100644 --- a/packages/forest_admin_agent/spec/lib/forest_admin_agent/routes/security/authentication_spec.rb +++ b/packages/forest_admin_agent/spec/lib/forest_admin_agent/routes/security/authentication_spec.rb @@ -56,7 +56,7 @@ module Security args = { params: {} } expect do authentication.handle_authentication args - end.to raise_error(ForestAdminAgent::Http::Exceptions::BadRequestError, + end.to raise_error(ForestAdminDatasourceToolkit::Exceptions::BadRequestError, ForestAdminAgent::Utils::ErrorMessages::MISSING_RENDERING_ID) end @@ -64,7 +64,7 @@ module Security args = { params: { 'renderingId' => 'abc' } } expect do authentication.handle_authentication args - end.to raise_error(ForestAdminAgent::Http::Exceptions::ValidationError, + end.to raise_error(ForestAdminDatasourceToolkit::Exceptions::ValidationError, ForestAdminAgent::Utils::ErrorMessages::INVALID_RENDERING_ID) end @@ -93,7 +93,7 @@ module Security expect do authentication.handle_authentication_callback args - end.to raise_error(ForestAdminAgent::Http::Exceptions::AuthenticationOpenIdClient) + end.to raise_error(ForestAdminDatasourceToolkit::Exceptions::AuthenticationOpenIdClient) end end diff --git a/packages/forest_admin_agent/spec/lib/forest_admin_agent/services/ip_whitelist_spec.rb b/packages/forest_admin_agent/spec/lib/forest_admin_agent/services/ip_whitelist_spec.rb index 3cd75b6ee..0d6a00f6f 100644 --- a/packages/forest_admin_agent/spec/lib/forest_admin_agent/services/ip_whitelist_spec.rb +++ b/packages/forest_admin_agent/spec/lib/forest_admin_agent/services/ip_whitelist_spec.rb @@ -55,7 +55,7 @@ module Services it 'raises an error without parsing JSON' do expect do ip_whitelist.enabled? - end.to raise_error(ForestAdminAgent::Http::Exceptions::InternalServerError, ForestAdminAgent::Utils::ErrorMessages::UNEXPECTED) + end.to raise_error(ForestAdminDatasourceToolkit::Exceptions::InternalServerError, ForestAdminAgent::Utils::ErrorMessages::UNEXPECTED) end end @@ -71,7 +71,7 @@ module Services it 'raises an error without parsing JSON' do expect do ip_whitelist.enabled? - end.to raise_error(ForestAdminAgent::Http::Exceptions::InternalServerError, ForestAdminAgent::Utils::ErrorMessages::UNEXPECTED) + end.to raise_error(ForestAdminDatasourceToolkit::Exceptions::InternalServerError, ForestAdminAgent::Utils::ErrorMessages::UNEXPECTED) end end @@ -87,7 +87,7 @@ module Services it 'raises an error without parsing JSON' do expect do ip_whitelist.enabled? - end.to raise_error(ForestAdminAgent::Http::Exceptions::InternalServerError, ForestAdminAgent::Utils::ErrorMessages::UNEXPECTED) + end.to raise_error(ForestAdminDatasourceToolkit::Exceptions::InternalServerError, ForestAdminAgent::Utils::ErrorMessages::UNEXPECTED) end end @@ -105,7 +105,7 @@ module Services it 'raises an error' do expect do ip_whitelist.enabled? - end.to raise_error(ForestAdminAgent::Http::Exceptions::InternalServerError, ForestAdminAgent::Utils::ErrorMessages::UNEXPECTED) + end.to raise_error(ForestAdminDatasourceToolkit::Exceptions::InternalServerError, ForestAdminAgent::Utils::ErrorMessages::UNEXPECTED) end end @@ -123,7 +123,7 @@ module Services it 'raises an error' do expect do ip_whitelist.enabled? - end.to raise_error(ForestAdminAgent::Http::Exceptions::InternalServerError, ForestAdminAgent::Utils::ErrorMessages::UNEXPECTED) + end.to raise_error(ForestAdminDatasourceToolkit::Exceptions::InternalServerError, ForestAdminAgent::Utils::ErrorMessages::UNEXPECTED) end end diff --git a/packages/forest_admin_agent/spec/lib/forest_admin_agent/services/permissions_spec.rb b/packages/forest_admin_agent/spec/lib/forest_admin_agent/services/permissions_spec.rb index b13eb94dd..f7c86474e 100644 --- a/packages/forest_admin_agent/spec/lib/forest_admin_agent/services/permissions_spec.rb +++ b/packages/forest_admin_agent/spec/lib/forest_admin_agent/services/permissions_spec.rb @@ -6,7 +6,6 @@ module ForestAdminAgent module Services include ForestAdminAgent::Utils - include ForestAdminAgent::Http::Exceptions include ForestAdminDatasourceToolkit include ForestAdminDatasourceToolkit::Schema include ForestAdminDatasourceToolkit::Components::Query @@ -1035,7 +1034,7 @@ module Services expect do @permissions.can_smart_action?(args, @datasource.collections['Book'], Filter.new) - end.to raise_error(ForestAdminAgent::Http::Exceptions::BadRequestError, 'The collection Book does not have this smart action') + end.to raise_error(ForestAdminDatasourceToolkit::Exceptions::BadRequestError, 'The collection Book does not have this smart action') end it "throws when the forest schema doesn't have any actions" do @@ -1068,7 +1067,7 @@ module Services expect do @permissions.can_smart_action?(args, @datasource.collections['Book'], Filter.new) - end.to raise_error(ForestAdminAgent::Http::Exceptions::BadRequestError, 'The collection Book does not have this smart action') + end.to raise_error(ForestAdminDatasourceToolkit::Exceptions::BadRequestError, 'The collection Book does not have this smart action') end end end diff --git a/packages/forest_admin_agent/spec/lib/forest_admin_agent/services/smart_action_checker_spec.rb b/packages/forest_admin_agent/spec/lib/forest_admin_agent/services/smart_action_checker_spec.rb index 6c7d9c5ec..07d9dcc69 100644 --- a/packages/forest_admin_agent/spec/lib/forest_admin_agent/services/smart_action_checker_spec.rb +++ b/packages/forest_admin_agent/spec/lib/forest_admin_agent/services/smart_action_checker_spec.rb @@ -2,7 +2,7 @@ module ForestAdminAgent module Services - include ForestAdminAgent::Http::Exceptions + include ForestAdminDatasourceToolkit::Exceptions include ForestAdminAgent::Utils include ForestAdminDatasourceToolkit include ForestAdminDatasourceToolkit::Schema diff --git a/packages/forest_admin_agent/spec/lib/forest_admin_agent/utils/condition_tree_parser_spec.rb b/packages/forest_admin_agent/spec/lib/forest_admin_agent/utils/condition_tree_parser_spec.rb index e7ba637fd..b8f478b36 100644 --- a/packages/forest_admin_agent/spec/lib/forest_admin_agent/utils/condition_tree_parser_spec.rb +++ b/packages/forest_admin_agent/spec/lib/forest_admin_agent/utils/condition_tree_parser_spec.rb @@ -32,7 +32,7 @@ module Utils expect do condition_tree_parser.from_plain_object(collection_category, {}) - end.to raise_error(ForestAdminAgent::Http::Exceptions::BadRequestError, 'Failed to instantiate condition tree') + end.to raise_error(ForestAdminDatasourceToolkit::Exceptions::BadRequestError, 'Failed to instantiate condition tree') end it 'works with aggregator' do diff --git a/packages/forest_admin_agent/spec/lib/forest_admin_agent/utils/query_string_parser_spec.rb b/packages/forest_admin_agent/spec/lib/forest_admin_agent/utils/query_string_parser_spec.rb index 1c0c0df66..055490a31 100644 --- a/packages/forest_admin_agent/spec/lib/forest_admin_agent/utils/query_string_parser_spec.rb +++ b/packages/forest_admin_agent/spec/lib/forest_admin_agent/utils/query_string_parser_spec.rb @@ -7,6 +7,7 @@ module Utils include ForestAdminDatasourceToolkit::Components::Query include ForestAdminDatasourceToolkit::Components::Query::ConditionTree include ForestAdminDatasourceToolkit::Components::Query::ConditionTree::Nodes + include ForestAdminDatasourceToolkit::Exceptions describe QueryStringParser do include_context 'with caller' @@ -35,7 +36,7 @@ module Utils expect do described_class.parse_caller(args) end.to raise_error( - Http::Exceptions::BadRequestError, + BadRequestError, 'Missing timezone' ) end @@ -52,7 +53,7 @@ module Utils expect do described_class.parse_caller(args) end.to raise_error( - Http::Exceptions::BadRequestError, + BadRequestError, 'Invalid timezone: foo/timezone' ) end @@ -67,7 +68,7 @@ module Utils expect do described_class.parse_caller(args) end.to raise_error( - Http::Exceptions::UnauthorizedError, + UnauthorizedError, 'You must be logged in to access at this resource.' ) end @@ -341,7 +342,7 @@ module Utils expect do described_class.parse_pagination(args) end.to raise_error( - Http::Exceptions::BadRequestError, + BadRequestError, 'Invalid pagination [limit: -5, skip: NaN]' ) end @@ -358,7 +359,7 @@ module Utils expect do described_class.parse_pagination(args) end.to raise_error( - Http::Exceptions::BadRequestError, + BadRequestError, 'Invalid pagination [limit: abc, skip: 1]' ) end @@ -373,7 +374,7 @@ module Utils expect do described_class.parse_pagination(args) end.to raise_error( - Http::Exceptions::BadRequestError, + BadRequestError, 'Invalid pagination [limit: -50, skip: 1]' ) end @@ -388,7 +389,7 @@ module Utils expect do described_class.parse_pagination(args) end.to raise_error( - Http::Exceptions::BadRequestError, + BadRequestError, 'Invalid pagination [limit: 0, skip: 1]' ) end @@ -403,7 +404,7 @@ module Utils expect do described_class.parse_pagination(args) end.to raise_error( - Http::Exceptions::BadRequestError, + BadRequestError, 'Invalid pagination [limit: 1.5, skip: 1]' ) end @@ -420,7 +421,7 @@ module Utils expect do described_class.parse_pagination(args) end.to raise_error( - Http::Exceptions::BadRequestError, + BadRequestError, 'Invalid pagination [limit: 50, skip: invalid]' ) end @@ -435,7 +436,7 @@ module Utils expect do described_class.parse_pagination(args) end.to raise_error( - Http::Exceptions::BadRequestError, + BadRequestError, 'Invalid pagination [limit: 50, skip: -1]' ) end @@ -450,7 +451,7 @@ module Utils expect do described_class.parse_pagination(args) end.to raise_error( - Http::Exceptions::BadRequestError, + BadRequestError, 'Invalid pagination [limit: 50, skip: 1.5]' ) end @@ -465,7 +466,7 @@ module Utils expect do described_class.parse_pagination(args) end.to raise_error( - Http::Exceptions::BadRequestError, + BadRequestError, "Invalid pagination [limit: 50, skip: '; DROP TABLE users--]" ) end @@ -585,7 +586,7 @@ module Utils expect do described_class.parse_search(collection_category, args) end.to raise_error( - Http::Exceptions::BadRequestError, + BadRequestError, 'Collection is not searchable' ) end diff --git a/packages/forest_admin_agent/spec/lib/forest_admin_agent/utils/query_validator_spec.rb b/packages/forest_admin_agent/spec/lib/forest_admin_agent/utils/query_validator_spec.rb index d384166bb..3f0d1f3f8 100644 --- a/packages/forest_admin_agent/spec/lib/forest_admin_agent/utils/query_validator_spec.rb +++ b/packages/forest_admin_agent/spec/lib/forest_admin_agent/utils/query_validator_spec.rb @@ -49,43 +49,43 @@ module Utils describe 'queries that raise exceptions' do it 'raises an error for an empty query' do query = ' ' - expect { described_class.valid?(query) }.to raise_error(Http::Exceptions::BadRequestError, 'Query cannot be empty.') + expect { described_class.valid?(query) }.to raise_error(BadRequestError, 'Query cannot be empty.') end it 'raises an error for non-SELECT queries' do query = 'DELETE FROM users;' - expect { described_class.valid?(query) }.to raise_error(Http::Exceptions::BadRequestError, 'Only SELECT queries are allowed.') + expect { described_class.valid?(query) }.to raise_error(BadRequestError, 'Only SELECT queries are allowed.') end it 'raises an error for multiple queries' do query = 'SELECT * FROM users; SELECT * FROM orders;' - expect { described_class.valid?(query) }.to raise_error(Http::Exceptions::BadRequestError, 'Only one query is allowed.') + expect { described_class.valid?(query) }.to raise_error(BadRequestError, 'Only one query is allowed.') end it 'raises an error for unbalanced parentheses outside WHERE clause' do query = 'SELECT (id, name FROM users WHERE (id > 1);' - expect { described_class.valid?(query) }.to raise_error(Http::Exceptions::BadRequestError, 'The query contains unbalanced parentheses.') + expect { described_class.valid?(query) }.to raise_error(BadRequestError, 'The query contains unbalanced parentheses.') end it 'raises an error for a semicolon not at the end of the query' do query = 'SELECT * FROM users; WHERE id > 1' - expect { described_class.valid?(query) }.to raise_error(Http::Exceptions::BadRequestError, 'Semicolon must only appear as the last character in the query.') + expect { described_class.valid?(query) }.to raise_error(BadRequestError, 'Semicolon must only appear as the last character in the query.') end it 'raises an error for forbidden keywords even inside subqueries' do query = 'SELECT * FROM users WHERE id IN (DROP TABLE users);' - expect { described_class.valid?(query) }.to raise_error(Http::Exceptions::BadRequestError, 'The query contains forbidden keyword: DROP.') + expect { described_class.valid?(query) }.to raise_error(BadRequestError, 'The query contains forbidden keyword: DROP.') end it 'raises an error for unbalanced parentheses in subqueries' do query = 'SELECT * FROM (SELECT id, name FROM users WHERE id > 1;' - expect { described_class.valid?(query) }.to raise_error(Http::Exceptions::BadRequestError, 'The query contains unbalanced parentheses.') + expect { described_class.valid?(query) }.to raise_error(BadRequestError, 'The query contains unbalanced parentheses.') end it 'raises an error for an OR-based injection' do query = "SELECT * FROM users WHERE username = 'admin' OR 1=1;" expect { described_class.valid?(query) } - .to raise_error(Http::Exceptions::BadRequestError, 'The query contains a potential SQL injection pattern.') + .to raise_error(BadRequestError, 'The query contains a potential SQL injection pattern.') end end end diff --git a/packages/forest_admin_datasource_active_record/lib/forest_admin_datasource_active_record/datasource.rb b/packages/forest_admin_datasource_active_record/lib/forest_admin_datasource_active_record/datasource.rb index 9285f2d72..ee7cb1dda 100644 --- a/packages/forest_admin_datasource_active_record/lib/forest_admin_datasource_active_record/datasource.rb +++ b/packages/forest_admin_datasource_active_record/lib/forest_admin_datasource_active_record/datasource.rb @@ -29,7 +29,7 @@ def initialize( def execute_native_query(connection_name, query, binds) unless @live_query_connections[connection_name] - raise ForestAdminAgent::Http::Exceptions::NotFoundError, + raise ForestAdminDatasourceToolkit::Exceptions::NotFoundError, "Native query connection '#{connection_name}' is unknown." end diff --git a/packages/forest_admin_datasource_customizer/lib/forest_admin_datasource_customizer/decorators/hook/context/hook_context.rb b/packages/forest_admin_datasource_customizer/lib/forest_admin_datasource_customizer/decorators/hook/context/hook_context.rb index 3411252f8..1a02e17b6 100644 --- a/packages/forest_admin_datasource_customizer/lib/forest_admin_datasource_customizer/decorators/hook/context/hook_context.rb +++ b/packages/forest_admin_datasource_customizer/lib/forest_admin_datasource_customizer/decorators/hook/context/hook_context.rb @@ -3,7 +3,7 @@ module Decorators module Hook module Context class HookContext < ForestAdminDatasourceCustomizer::Context::CollectionCustomizationContext - include ForestAdminAgent::Http::Exceptions + include ForestAdminDatasourceToolkit::Exceptions def raise_validation_error(message) raise ValidationError, message end diff --git a/packages/forest_admin_datasource_customizer/spec/lib/forest_admin_datasource_customizer/datasource_customizer_spec.rb b/packages/forest_admin_datasource_customizer/spec/lib/forest_admin_datasource_customizer/datasource_customizer_spec.rb index 8c129335a..9dddc6df1 100644 --- a/packages/forest_admin_datasource_customizer/spec/lib/forest_admin_datasource_customizer/datasource_customizer_spec.rb +++ b/packages/forest_admin_datasource_customizer/spec/lib/forest_admin_datasource_customizer/datasource_customizer_spec.rb @@ -2,7 +2,7 @@ module ForestAdminDatasourceCustomizer include ForestAdminDatasourceToolkit::Schema - include ForestAdminAgent::Http::Exceptions + include ForestAdminDatasourceToolkit::Exceptions describe DatasourceCustomizer do let(:datasource) { ForestAdminDatasourceToolkit::Datasource.new } diff --git a/packages/forest_admin_datasource_customizer/spec/lib/forest_admin_datasource_customizer/decorators/hook/context/hook_context_spec.rb b/packages/forest_admin_datasource_customizer/spec/lib/forest_admin_datasource_customizer/decorators/hook/context/hook_context_spec.rb index 19d1764f5..3ab40559c 100644 --- a/packages/forest_admin_datasource_customizer/spec/lib/forest_admin_datasource_customizer/decorators/hook/context/hook_context_spec.rb +++ b/packages/forest_admin_datasource_customizer/spec/lib/forest_admin_datasource_customizer/decorators/hook/context/hook_context_spec.rb @@ -16,7 +16,7 @@ module Context it 'raise an UnprocessableError' do expect do hook_context.raise_error('message exception') - end.to raise_error(ForestAdminAgent::Http::Exceptions::UnprocessableError, 'message exception') + end.to raise_error(ForestAdminDatasourceToolkit::Exceptions::UnprocessableError, 'message exception') end end @@ -24,7 +24,7 @@ module Context it 'raise an ForbiddenError' do expect do hook_context.raise_forbidden_error('message exception') - end.to raise_error(ForestAdminAgent::Http::Exceptions::ForbiddenError, 'message exception') + end.to raise_error(ForestAdminDatasourceToolkit::Exceptions::ForbiddenError, 'message exception') end end @@ -32,7 +32,7 @@ module Context it 'raise an ValidationError' do expect do hook_context.raise_validation_error('message exception') - end.to raise_error(ForestAdminAgent::Http::Exceptions::ValidationError, 'message exception') + end.to raise_error(ForestAdminDatasourceToolkit::Exceptions::ValidationError, 'message exception') end end end diff --git a/packages/forest_admin_datasource_customizer/spec/lib/forest_admin_datasource_customizer/decorators/operators_emulate/operators_emulate_collection_decorator_spec.rb b/packages/forest_admin_datasource_customizer/spec/lib/forest_admin_datasource_customizer/decorators/operators_emulate/operators_emulate_collection_decorator_spec.rb index e995f39ad..2ee4c13e8 100644 --- a/packages/forest_admin_datasource_customizer/spec/lib/forest_admin_datasource_customizer/decorators/operators_emulate/operators_emulate_collection_decorator_spec.rb +++ b/packages/forest_admin_datasource_customizer/spec/lib/forest_admin_datasource_customizer/decorators/operators_emulate/operators_emulate_collection_decorator_spec.rb @@ -125,7 +125,7 @@ module OperatorsEmulate expect do @decorated_book.list(caller, filter, projection) - end.to raise_error(Exceptions::ForestException, "The given operator 'like' is not supported by the column: 'title'. The column is not filterable") + end.to raise_error(Exceptions::ValidationError, "The given operator 'like' is not supported by the column: 'title'. The column is not filterable") end end diff --git a/packages/forest_admin_datasource_customizer/spec/lib/forest_admin_datasource_customizer/decorators/write/write_replace/collection_basics_spec.rb b/packages/forest_admin_datasource_customizer/spec/lib/forest_admin_datasource_customizer/decorators/write/write_replace/collection_basics_spec.rb index b5d374978..9c17d9e57 100644 --- a/packages/forest_admin_datasource_customizer/spec/lib/forest_admin_datasource_customizer/decorators/write/write_replace/collection_basics_spec.rb +++ b/packages/forest_admin_datasource_customizer/spec/lib/forest_admin_datasource_customizer/decorators/write/write_replace/collection_basics_spec.rb @@ -34,7 +34,7 @@ module WriteReplace @decorated_book.replace_field_writing('__dontExist') do {} end - end.to raise_error(ForestException, "Column not found: 'book.__dontExist'") + end.to raise_error(ValidationError, "Column not found: 'book.__dontExist'") end it 'marks fields as writable when handler is defined' do diff --git a/packages/forest_admin_datasource_rpc/lib/forest_admin_datasource_rpc/Utils/rpc_client.rb b/packages/forest_admin_datasource_rpc/lib/forest_admin_datasource_rpc/Utils/rpc_client.rb index c7a21f672..215df7378 100644 --- a/packages/forest_admin_datasource_rpc/lib/forest_admin_datasource_rpc/Utils/rpc_client.rb +++ b/packages/forest_admin_datasource_rpc/lib/forest_admin_datasource_rpc/Utils/rpc_client.rb @@ -20,12 +20,12 @@ class RpcClient # Map HTTP status codes to Forest Admin exception classes ERROR_STATUS_MAP = { - 400 => ForestAdminAgent::Http::Exceptions::ValidationError, - 401 => ForestAdminAgent::Http::Exceptions::AuthenticationOpenIdClient, - 403 => ForestAdminAgent::Http::Exceptions::ForbiddenError, - 404 => ForestAdminAgent::Http::Exceptions::NotFoundError, - 409 => ForestAdminAgent::Http::Exceptions::ConflictError, - 422 => ForestAdminAgent::Http::Exceptions::UnprocessableError + 400 => ForestAdminDatasourceToolkit::Exceptions::ValidationError, + 401 => ForestAdminDatasourceToolkit::Exceptions::AuthenticationOpenIdClient, + 403 => ForestAdminDatasourceToolkit::Exceptions::ForbiddenError, + 404 => ForestAdminDatasourceToolkit::Exceptions::NotFoundError, + 409 => ForestAdminDatasourceToolkit::Exceptions::ConflictError, + 422 => ForestAdminDatasourceToolkit::Exceptions::UnprocessableError }.freeze def initialize(api_url, auth_secret) diff --git a/packages/forest_admin_datasource_rpc/spec/lib/forest_admin_datasource_rpc/utils/rpc_client_spec.rb b/packages/forest_admin_datasource_rpc/spec/lib/forest_admin_datasource_rpc/utils/rpc_client_spec.rb index 570e480f2..30d4fde35 100644 --- a/packages/forest_admin_datasource_rpc/spec/lib/forest_admin_datasource_rpc/utils/rpc_client_spec.rb +++ b/packages/forest_admin_datasource_rpc/spec/lib/forest_admin_datasource_rpc/utils/rpc_client_spec.rb @@ -112,7 +112,7 @@ module Utils it 'raises ValidationError with error message' do expect { rpc_client.call_rpc(url, method: :get) }.to raise_error( - ForestAdminAgent::Http::Exceptions::ValidationError, + ForestAdminDatasourceToolkit::Exceptions::ValidationError, /Invalid parameters/ ) end @@ -131,7 +131,7 @@ module Utils it 'raises AuthenticationOpenIdClient error' do expect { rpc_client.call_rpc(url, method: :get) }.to raise_error( - ForestAdminAgent::Http::Exceptions::AuthenticationOpenIdClient, + ForestAdminDatasourceToolkit::Exceptions::AuthenticationOpenIdClient, /Invalid credentials/ ) end @@ -150,7 +150,7 @@ module Utils it 'raises ForbiddenError' do expect { rpc_client.call_rpc(url, method: :get) }.to raise_error( - ForestAdminAgent::Http::Exceptions::ForbiddenError, + ForestAdminDatasourceToolkit::Exceptions::ForbiddenError, /Access denied/ ) end @@ -169,7 +169,7 @@ module Utils it 'raises NotFoundError' do expect { rpc_client.call_rpc(url, method: :get) }.to raise_error( - ForestAdminAgent::Http::Exceptions::NotFoundError, + ForestAdminDatasourceToolkit::Exceptions::NotFoundError, /Resource not found/ ) end @@ -188,7 +188,7 @@ module Utils it 'raises ConflictError' do expect { rpc_client.call_rpc(url, method: :get) }.to raise_error( - ForestAdminAgent::Http::Exceptions::ConflictError, + ForestAdminDatasourceToolkit::Exceptions::ConflictError, /Duplicate record/ ) end @@ -207,7 +207,7 @@ module Utils it 'raises UnprocessableError' do expect { rpc_client.call_rpc(url, method: :get) }.to raise_error( - ForestAdminAgent::Http::Exceptions::UnprocessableError, + ForestAdminDatasourceToolkit::Exceptions::UnprocessableError, /Validation failed/ ) end @@ -264,7 +264,7 @@ module Utils it 'extracts message correctly' do expect { rpc_client.call_rpc(url, method: :get) }.to raise_error( - ForestAdminAgent::Http::Exceptions::ValidationError, + ForestAdminDatasourceToolkit::Exceptions::ValidationError, /Custom error message/ ) end diff --git a/packages/forest_admin_datasource_toolkit/lib/forest_admin_datasource_toolkit.rb b/packages/forest_admin_datasource_toolkit/lib/forest_admin_datasource_toolkit.rb index 57c965153..7df8f36ed 100644 --- a/packages/forest_admin_datasource_toolkit/lib/forest_admin_datasource_toolkit.rb +++ b/packages/forest_admin_datasource_toolkit/lib/forest_admin_datasource_toolkit.rb @@ -1,10 +1,11 @@ require_relative "forest_admin_datasource_toolkit/version" +require_relative "forest_admin_datasource_toolkit/exceptions/business_error" require 'zeitwerk' loader = Zeitwerk::Loader.for_gem loader.setup module ForestAdminDatasourceToolkit - class Error < StandardError; end + class Error < BusinessError; end # Your code goes here... end diff --git a/packages/forest_admin_datasource_toolkit/lib/forest_admin_datasource_toolkit/exceptions/business_error.rb b/packages/forest_admin_datasource_toolkit/lib/forest_admin_datasource_toolkit/exceptions/business_error.rb new file mode 100644 index 000000000..dcfe45607 --- /dev/null +++ b/packages/forest_admin_datasource_toolkit/lib/forest_admin_datasource_toolkit/exceptions/business_error.rb @@ -0,0 +1,99 @@ +module ForestAdminDatasourceToolkit + module Exceptions + # Parent class for all business errors + # This is the base class that all specific error types inherit from + class BusinessError < StandardError + attr_reader :details, :cause + + def initialize(message = nil, details: {}, cause: nil) + super(message) + @details = details || {} + @cause = cause + end + + # Returns the name of the error class + def name + self.class.name.split('::').last + end + end + + # ==================== + # Specific error types + # ==================== + + class BadRequestError < BusinessError + def initialize(message = 'Bad request', details: {}) + super + end + end + + class ValidationError < BadRequestError + def initialize(message = 'Validation failed', details: {}) + super + end + end + + class UnauthorizedError < BusinessError + def initialize(message = 'Unauthorized', details: {}) + super + end + end + + class AuthenticationOpenIdClient < UnauthorizedError + def initialize(message = 'Authentication failed with OpenID Client', details: {}) + super + end + end + + class ForbiddenError < BusinessError + def initialize(message = 'Forbidden', details: {}) + super + end + end + + class NotFoundError < BusinessError + def initialize(message, details: {}) + super + end + end + + class ConflictError < BusinessError + def initialize(message = 'Conflict', details: {}) + super + end + end + + class UnprocessableError < BusinessError + def initialize(message = 'Unprocessable entity', details: {}) + super + end + end + + class TooManyRequestsError < BusinessError + attr_reader :retry_after + + def initialize(message, retry_after, details: {}) + super(message, details: details) + @retry_after = retry_after + end + end + + class InternalServerError < BusinessError + def initialize(message = 'Internal server error', details: {}, cause: nil) + super + end + end + + class BadGatewayError < BusinessError + def initialize(message = 'Bad gateway error', details: {}, cause: nil) + super + end + end + + class ServiceUnavailableError < BusinessError + def initialize(message = 'Service unavailable error', details: {}, cause: nil) + super + end + end + end +end diff --git a/packages/forest_admin_datasource_toolkit/lib/forest_admin_datasource_toolkit/exceptions/validation_error.rb b/packages/forest_admin_datasource_toolkit/lib/forest_admin_datasource_toolkit/exceptions/validation_error.rb deleted file mode 100644 index 130b4e27a..000000000 --- a/packages/forest_admin_datasource_toolkit/lib/forest_admin_datasource_toolkit/exceptions/validation_error.rb +++ /dev/null @@ -1,12 +0,0 @@ -module ForestAdminDatasourceToolkit - module Exceptions - class ValidationError < ForestException - attr_reader :name - - def initialize(message) - @name = 'ValidationError' - super - end - end - end -end diff --git a/packages/forest_admin_datasource_toolkit/spec/lib/forest_admin_datasource_toolkit/validations/record_validator_spec.rb b/packages/forest_admin_datasource_toolkit/spec/lib/forest_admin_datasource_toolkit/validations/record_validator_spec.rb index eeedfa9f8..c75fa5c53 100644 --- a/packages/forest_admin_datasource_toolkit/spec/lib/forest_admin_datasource_toolkit/validations/record_validator_spec.rb +++ b/packages/forest_admin_datasource_toolkit/spec/lib/forest_admin_datasource_toolkit/validations/record_validator_spec.rb @@ -41,7 +41,7 @@ module Validations it 'throws an error' do expect do described_class.validate(@collection, { 'name' => [100] }) - end.to raise_error(ForestException, "The given value has a wrong type for 'name': 100.\n Expects [\"String\", nil]") + end.to raise_error(ValidationError, "The given value has a wrong type for 'name': 100.\n Expects [\"String\", nil]") end end end diff --git a/packages/forest_admin_rails/app/controllers/forest_admin_rails/forest_controller.rb b/packages/forest_admin_rails/app/controllers/forest_admin_rails/forest_controller.rb index a713430ec..94bccbc33 100644 --- a/packages/forest_admin_rails/app/controllers/forest_admin_rails/forest_controller.rb +++ b/packages/forest_admin_rails/app/controllers/forest_admin_rails/forest_controller.rb @@ -66,7 +66,7 @@ def exception_handler(exception) response.headers.merge!(http_exception.custom_headers || {}) data = case exception - when ForestAdminAgent::Http::Exceptions::AuthenticationOpenIdClient, + when ForestAdminDatasourceToolkit::Exceptions::AuthenticationOpenIdClient, OpenIDConnect::Exception { error: exception.message, diff --git a/packages/forest_admin_rails/spec/controllers/forest_admin_rails/forest_controller_spec.rb b/packages/forest_admin_rails/spec/controllers/forest_admin_rails/forest_controller_spec.rb index fdb2acb28..c52b5baa8 100644 --- a/packages/forest_admin_rails/spec/controllers/forest_admin_rails/forest_controller_spec.rb +++ b/packages/forest_admin_rails/spec/controllers/forest_admin_rails/forest_controller_spec.rb @@ -28,7 +28,7 @@ module ForestAdminRails describe '#exception_handler' do context 'when exception is AuthenticationOpenIdClient' do it 'returns OpenID error format with real exception' do - exception = ForestAdminAgent::Http::Exceptions::AuthenticationOpenIdClient.new('Auth failed') + exception = ForestAdminDatasourceToolkit::Exceptions::AuthenticationOpenIdClient.new('Auth failed') # Define response as singleton method for this instance exception.define_singleton_method(:response) { 'Invalid token' } @@ -55,7 +55,7 @@ module ForestAdminRails allow(exception).to receive(:full_message).and_return('Full error trace') # Make the case/when work by stubbing the === method - allow(ForestAdminAgent::Http::Exceptions::AuthenticationOpenIdClient).to receive(:===).with(exception).and_return(true) + allow(ForestAdminDatasourceToolkit::Exceptions::AuthenticationOpenIdClient).to receive(:===).with(exception).and_return(true) allow(OpenIDConnect::Exception).to receive(:===).with(exception).and_return(false) controller.send(:exception_handler, exception) @@ -83,7 +83,7 @@ module ForestAdminRails allow(exception).to receive(:full_message).and_return('Full error trace') # Make the case/when work by stubbing the === method - allow(ForestAdminAgent::Http::Exceptions::AuthenticationOpenIdClient).to receive(:===).with(exception).and_return(false) + allow(ForestAdminDatasourceToolkit::Exceptions::AuthenticationOpenIdClient).to receive(:===).with(exception).and_return(false) allow(OpenIDConnect::Exception).to receive(:===).with(exception).and_return(true) controller.send(:exception_handler, exception) @@ -98,7 +98,7 @@ module ForestAdminRails context 'with ValidationError' do it 'returns errors format with validation error details' do - exception = ForestAdminAgent::Http::Exceptions::ValidationError.new('Email is invalid') + exception = ForestAdminDatasourceToolkit::Exceptions::ValidationError.new('Email is invalid') # Mock get_error_message to work with real HttpException instances # Note: get_error_message has a bug where it checks error.ancestors instead of error.class.ancestors controller.send(:exception_handler, exception) @@ -114,7 +114,7 @@ module ForestAdminRails end it 'supports custom name' do - exception = ForestAdminAgent::Http::Exceptions::ValidationError.new('Invalid data') + exception = ForestAdminDatasourceToolkit::Exceptions::ValidationError.new('Invalid data') controller.send(:exception_handler, exception) json = JSON.parse(response_mock.body) @@ -124,7 +124,7 @@ module ForestAdminRails context 'with ForbiddenError' do it 'returns errors format with 403 status' do - exception = ForestAdminAgent::Http::Exceptions::ForbiddenError.new('Access denied') + exception = ForestAdminDatasourceToolkit::Exceptions::ForbiddenError.new('Access denied') controller.send(:exception_handler, exception) expect(response_mock.status).to eq(403) @@ -137,7 +137,7 @@ module ForestAdminRails context 'with NotFoundError' do it 'returns errors format with 404 status' do - exception = ForestAdminAgent::Http::Exceptions::NotFoundError.new('Resource not found') + exception = ForestAdminDatasourceToolkit::Exceptions::NotFoundError.new('Resource not found') controller.send(:exception_handler, exception) expect(response_mock.status).to eq(404) @@ -162,8 +162,8 @@ module ForestAdminRails allow(exception).to receive(:try).with(:status).and_return(nil) allow(exception).to receive(:try).with(:data).and_return(nil) allow(exception).to receive(:is_a?).with(ForestAdminAgent::Http::Exceptions::HttpException).and_return(false) - allow(exception).to receive(:is_a?).with(ForestAdminAgent::Http::Exceptions::BusinessError).and_return(false) - allow(exception).to receive(:is_a?).with(ForestAdminAgent::Http::Exceptions::AuthenticationOpenIdClient).and_return(false) + allow(exception).to receive(:is_a?).with(ForestAdminDatasourceToolkit::Exceptions::BusinessError).and_return(false) + allow(exception).to receive(:is_a?).with(ForestAdminDatasourceToolkit::Exceptions::AuthenticationOpenIdClient).and_return(false) allow(exception).to receive(:is_a?).with(OpenIDConnect::Exception).and_return(false) allow(exception).to receive(:full_message).and_return('Full error') @@ -190,8 +190,8 @@ module ForestAdminRails allow(exception).to receive(:try).with(:status).and_return(nil) allow(exception).to receive(:try).with(:data).and_return(nil) allow(exception).to receive(:is_a?).with(ForestAdminAgent::Http::Exceptions::HttpException).and_return(false) - allow(exception).to receive(:is_a?).with(ForestAdminAgent::Http::Exceptions::BusinessError).and_return(false) - allow(exception).to receive(:is_a?).with(ForestAdminAgent::Http::Exceptions::AuthenticationOpenIdClient).and_return(false) + allow(exception).to receive(:is_a?).with(ForestAdminDatasourceToolkit::Exceptions::BusinessError).and_return(false) + allow(exception).to receive(:is_a?).with(ForestAdminDatasourceToolkit::Exceptions::AuthenticationOpenIdClient).and_return(false) allow(exception).to receive(:is_a?).with(OpenIDConnect::Exception).and_return(false) allow(exception).to receive(:full_message).and_return('Full error') @@ -219,8 +219,8 @@ module ForestAdminRails allow(exception).to receive(:try).with(:status).and_return(nil) allow(exception).to receive(:try).with(:data).and_return(nil) allow(exception).to receive(:is_a?).with(ForestAdminAgent::Http::Exceptions::HttpException).and_return(false) - allow(exception).to receive(:is_a?).with(ForestAdminAgent::Http::Exceptions::BusinessError).and_return(false) - allow(exception).to receive(:is_a?).with(ForestAdminAgent::Http::Exceptions::AuthenticationOpenIdClient).and_return(false) + allow(exception).to receive(:is_a?).with(ForestAdminDatasourceToolkit::Exceptions::BusinessError).and_return(false) + allow(exception).to receive(:is_a?).with(ForestAdminDatasourceToolkit::Exceptions::AuthenticationOpenIdClient).and_return(false) allow(exception).to receive(:is_a?).with(OpenIDConnect::Exception).and_return(false) allow(exception).to receive(:full_message).and_return('Full error') @@ -245,8 +245,8 @@ module ForestAdminRails allow(exception).to receive(:try).with(:status).and_return(nil) allow(exception).to receive(:try).with(:data).and_return(nil) allow(exception).to receive(:is_a?).with(ForestAdminAgent::Http::Exceptions::HttpException).and_return(false) - allow(exception).to receive(:is_a?).with(ForestAdminAgent::Http::Exceptions::BusinessError).and_return(false) - allow(exception).to receive(:is_a?).with(ForestAdminAgent::Http::Exceptions::AuthenticationOpenIdClient).and_return(false) + allow(exception).to receive(:is_a?).with(ForestAdminDatasourceToolkit::Exceptions::BusinessError).and_return(false) + allow(exception).to receive(:is_a?).with(ForestAdminDatasourceToolkit::Exceptions::AuthenticationOpenIdClient).and_return(false) allow(exception).to receive(:is_a?).with(OpenIDConnect::Exception).and_return(false) allow(exception).to receive(:full_message).and_return('Full error trace') allow(ForestAdminAgent::Facades::Container).to receive(:cache).with(:is_production).and_return(false) @@ -269,8 +269,8 @@ module ForestAdminRails allow(exception).to receive(:try).with(:status).and_return(nil) allow(exception).to receive(:try).with(:data).and_return(nil) allow(exception).to receive(:is_a?).with(ForestAdminAgent::Http::Exceptions::HttpException).and_return(false) - allow(exception).to receive(:is_a?).with(ForestAdminAgent::Http::Exceptions::BusinessError).and_return(false) - allow(exception).to receive(:is_a?).with(ForestAdminAgent::Http::Exceptions::AuthenticationOpenIdClient).and_return(false) + allow(exception).to receive(:is_a?).with(ForestAdminDatasourceToolkit::Exceptions::BusinessError).and_return(false) + allow(exception).to receive(:is_a?).with(ForestAdminDatasourceToolkit::Exceptions::AuthenticationOpenIdClient).and_return(false) allow(exception).to receive(:is_a?).with(OpenIDConnect::Exception).and_return(false) allow(exception).to receive(:full_message).and_return('Full error trace') allow(ForestAdminAgent::Facades::Container).to receive(:cache).with(:is_production).and_return(true)