Skip to content

Usecase: redirect from before block #66

@vladfaust

Description

@vladfaust
struct MyAction
  include Onyx::REST::Action

  params do
    query do
      type redirect : Bool
    end
  end
  
  before do
    redirect("https://google.com") if params.query.redirect
  end
end

Currently the callbacks.cr shard ignores the callbacks' return values.

Possible solutions:

  • Action#halt method and @halted : Bool = false variable. Action#call checks if the @halted is false before run
  before do
    halt(redirect("https://google.com")) if params.query.redirect
  end

  before do
    puts "Will be put anyway"
  end

But in this case further before callbacks are still run.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions