-
Notifications
You must be signed in to change notification settings - Fork 1
fix: replace all generic errors to specific HTTP errors #182
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 20 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
5e34ca6
fix: better error handling
2c8256f
fix: tests and error messages
84dd5ec
fix: tests
54ff91b
fix: tests
5f4f102
fix: merge main
7c41981
fix: tests
bd53fd6
fix: tests
a877bf0
fix: review
2dd18a7
fix: review
2d9bd28
fix: review
7ee2c21
fix: tests
ee96faf
fix: remove useless error classes
9b8e916
fix: remove readme
d6da6dd
fix: replace all generic errors to specific HTTP errors
b8558e6
fix: tests
2d5de32
fix: tests
ac38dfb
fix: tests
0574392
fix: tests
5c4f967
fix: tests
ee032a0
fix: test
0f5192b
fix: agent not starting
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,3 +19,5 @@ Gemfile.lock | |
| Gemfile-test.lock | ||
| *.gem | ||
| pkg/ | ||
|
|
||
| .claude/ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
packages/forest_admin_agent/lib/forest_admin_agent/http/Exceptions/business_error.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| 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 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 | ||
|
|
||
| # Specialized BadRequestError subclass | ||
| class ValidationFailedError < BadRequestError | ||
| def initialize(message = 'Validation failed', details: {}) | ||
| super | ||
| end | ||
| end | ||
|
|
||
| # Legacy ValidationError - kept for backward compatibility with HttpException-based code | ||
| # This extends HttpException rather than BusinessError to maintain compatibility | ||
| # New code should use ValidationFailedError instead | ||
| class ValidationError < BusinessError | ||
| def initialize(message = 'Validation error', details: {}) | ||
| super | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end |
13 changes: 0 additions & 13 deletions
13
packages/forest_admin_agent/lib/forest_admin_agent/http/Exceptions/conflict_error.rb
This file was deleted.
Oops, something went wrong.
13 changes: 0 additions & 13 deletions
13
packages/forest_admin_agent/lib/forest_admin_agent/http/Exceptions/forbidden_error.rb
This file was deleted.
Oops, something went wrong.
41 changes: 41 additions & 0 deletions
41
packages/forest_admin_agent/lib/forest_admin_agent/http/Exceptions/http_error.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| require_relative 'business_error' | ||
|
|
||
| module ForestAdminAgent | ||
| module Http | ||
| module Exceptions | ||
| # HttpError wraps a BusinessError and adds HTTP-specific properties | ||
| 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) | ||
| super(error.message) | ||
|
|
||
| @name = error.class.name.split('::').last | ||
| @status = status | ||
| @user_message = error.message || user_message | ||
| @meta = error.respond_to?(:details) ? error.details : {} | ||
| @cause = error | ||
|
|
||
| @custom_headers = if custom_headers_proc.respond_to?(:call) | ||
| custom_headers_proc.call(error) | ||
| else | ||
| {} | ||
| end | ||
| end | ||
| end | ||
|
|
||
| # Factory class to generate HTTP error classes for specific status codes | ||
| class HttpErrorFactory | ||
| def self.create_for_business_error(status, default_message, options = {}) | ||
| custom_headers_proc = options[:custom_headers] | ||
|
|
||
| Class.new(HttpError) do | ||
| define_method(:initialize) do |error, user_message = nil, meta = nil| | ||
| super(error, status, user_message || default_message, meta, custom_headers_proc) | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end | ||
11 changes: 0 additions & 11 deletions
11
packages/forest_admin_agent/lib/forest_admin_agent/http/Exceptions/not_found_error.rb
This file was deleted.
Oops, something went wrong.
14 changes: 0 additions & 14 deletions
14
packages/forest_admin_agent/lib/forest_admin_agent/http/Exceptions/require_approval.rb
This file was deleted.
Oops, something went wrong.
13 changes: 0 additions & 13 deletions
13
packages/forest_admin_agent/lib/forest_admin_agent/http/Exceptions/unprocessable_error.rb
This file was deleted.
Oops, something went wrong.
13 changes: 0 additions & 13 deletions
13
packages/forest_admin_agent/lib/forest_admin_agent/http/Exceptions/validation_error.rb
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function with many parameters (count = 5): initialize [qlty:function-parameters]