Skip to content
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

Add multiple success failures types #41

Merged
merged 20 commits into from
Feb 22, 2023
Merged

Conversation

bvicenzo
Copy link
Contributor

Allow Success, Failure, Check and Try to be multiple Types.

Closes issue: #39

This allows success or failure to be more than one type...
A real-world example of this use is an HTTP client where we want to give provide different rescues for different HTTP codes, but same treatment for any other code for the family. For example:

User::Save(attrs: { name: 'Joe' })
  .on_success(:created) { return 'User created' }
  .on_success(:ok) { return 'User Updated' }
  .on_success { return 'User Saved' }
  .on_failure(:unprocessable_entity) { |error| return "Invalid attributes #{error}" }
  .on_failure(:conflict) { return "User already exist." }
  .on_failure(:too_many_requests) { return 'You reached your limit. Try again latter' }
  .on_failure(:bad_gateway, :gateway_timeout, :service_unavailable, :internal_server_error) { |return| return 'temporary trouble. try again latter' }
  .on_failure(:client_error, :server_error) do |error|
    Sentry.capture_exception("Some unexpected client error happened: #{error}")
    return "Unknow error happened, please contact system administration"
  end

@bvicenzo bvicenzo added the feature request New feature or request label Feb 13, 2023
@bvicenzo bvicenzo self-assigned this Feb 13, 2023
Copy link
Member

@matheusbsilva matheusbsilva left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏 👏 Awesome!

I have a question though, does this change breaks compatibility with the current version?

README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
Co-authored-by: Matheus Batista <matheusbattista@hotmail.com>
@bvicenzo
Copy link
Contributor Author

@matheusbsilva Thanks for reviewing this ❤️

Man, the idea is to keep compatibility...

Providing just this new deprecation warning: https://github.com/Fretadao/f_service/pull/41/files#diff-53c2e1dfdeb23d78fffd5f40d1602d38df5bd3f5d9903d8ab3bcf52402bb473cR24

I've tested on some services from our Web system, and seems that it's working...

Could you test it against our Kippu system also?

Just pointing the Gemfile to this branch:

gem 'f_service', github: 'Fretadao/f_service', branch: 'bv-add-multiple-failures'

updating and run the system.

Copy link
Member

@j133y j133y left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🥇

lib/f_service/result/base.rb Show resolved Hide resolved
@bvicenzo bvicenzo merged commit 22d3e1c into master Feb 22, 2023
@bvicenzo bvicenzo deleted the bv-add-multiple-failures branch February 22, 2023 12:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants