Uh oh!
There was an error while loading. Please reload this page.
fix: replace all generic errors to specific HTTP errors - #182
Conversation
4 new issues
This is from Qlty Cloud, the successor to Code Climate Quality. Learn more. |
| class HttpError < StandardError | ||
| attr_reader :status, :user_message, :custom_headers, :meta, :cause, :name | ||
| def initialize(error, status, user_message = nil, _meta = nil, custom_headers_proc = nil) |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Diff Coverage: The code coverage on the diff in this pull request is 83.0%. Total Coverage: This PR will decrease coverage by 0.18%. File Coverage Changes
🛟 Help
This is from Qlty Cloud, the successor to Code Climate Quality. Learn more. |
| def get_error_message(error) | ||
| return error.user_message if error.is_a?(ForestAdminAgent::Http::Exceptions::HttpError) | ||
| if error.class.respond_to?(:ancestors) && error.class.ancestors.include?(ForestAdminAgent::Http::Exceptions::HttpException) | ||
| return error.message | ||
| end | ||
| if (customizer = ForestAdminAgent::Facades::Container.cache(:customize_error_message)) | ||
| return error.message if error.is_a?(ForestAdminAgent::Http::Exceptions::BusinessError) | ||
| if defined?(ForestAdminAgent::Facades) && | ||
| (customizer = ForestAdminAgent::Facades::Container.cache(:customize_error_message)) | ||
| message = eval(customizer).call(error) | ||
| return message if message | ||
| end | ||
| return error.message if error.is_a?(ForestAdminDatasourceToolkit::Exceptions::ValidationError) | ||
| 'Unexpected error' |
| def self.translate(error) # rubocop:disable Metrics/MethodLength | ||
| # Already an HttpError or HttpException - no translation needed | ||
| return error if error.is_a?(Exceptions::HttpError) | ||
| return error if error.respond_to?(:status) && error.status | ||
| # Translate DatasourceToolkit ValidationError to Agent BadRequestError | ||
| if defined?(ForestAdminDatasourceToolkit::Exceptions::ValidationError) && | ||
| error.is_a?(ForestAdminDatasourceToolkit::Exceptions::ValidationError) | ||
| error = Exceptions::BadRequestError.new(error.message) | ||
| end | ||
| # Translate BusinessError to HttpError with appropriate status code | ||
| case error | ||
| when Exceptions::BadRequestError, Exceptions::ValidationError | ||
| ERROR_400.new(error) | ||
| when Exceptions::ForbiddenError | ||
| ERROR_403.new(error) | ||
| when Exceptions::NotFoundError | ||
| ERROR_404.new(error) | ||
| when Exceptions::ConflictError | ||
| ERROR_409.new(error) | ||
| when Exceptions::UnprocessableError | ||
| ERROR_422.new(error) | ||
| when Exceptions::TooManyRequestsError | ||
| ERROR_429.new(error) | ||
| when Exceptions::InternalServerError | ||
| ERROR_500.new(error) | ||
| when Exceptions::BadGatewayError | ||
| ERROR_502.new(error) | ||
| when Exceptions::ServiceUnavailableError | ||
| ERROR_503.new(error) | ||
| else | ||
| # Unknown error type - return as-is, will be handled as 500 | ||
| error | ||
| end |
EnkiP
commented
Oct 29, 2025
closed in favor of #197 |
Definition of Done
General
Security