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

Setup server-side abort and error handler hooks for commands #113

Merged
merged 23 commits into from Jan 7, 2024

Conversation

hopsoft
Copy link
Owner

@hopsoft hopsoft commented Jan 3, 2024

Add's hooks to trap and handle Command aborts and errors.

Video Demo

Video demo

Example

class ApplicationCommand < TurboBoost::Commands::Command
  # Abort a command from a before callback by invoking `throw :abort`
  # before_command { throw :abort }

  # NOTE: Callbacks use throw/catch to manage control flow which means
  #       this is not a real error per se, but you can intercept with rescue_from
  rescue_from TurboBoost::Commands::AbortError do |error|
    # do something...
  end

  # Setup an error handler with `on_error`
  rescue_from TurboBoost::Commands::PerformError do |error|
    # do something...
  end
end

Abort Visibility

Aborts will return an HTTP status of 285 instead of 200 along with some HTTP Headers to improve debuggability.

Error Visibility

Errors return an HTTP status of 5XX along with some HTTP Headers to improve debuggability. Error handling works if an error is raised in a Command lifecycle callback (before_command, etc.) or if raised from within the Command's perform method.

HTTP Headers

This PR introduces 2 new HTTP Headers to help with debugging.

  • TurboBoost-Command - Name of the Command that was invoked
  • TurboBoost-Command-Status - Status and info regarding Command invocation

@hopsoft hopsoft merged commit 08a9ef8 into main Jan 7, 2024
10 checks passed
@hopsoft hopsoft deleted the hopsoft/command-handlers branch January 7, 2024 16:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant