http icon indicating copy to clipboard operation
http copied to clipboard

Usecase: redirect from before block

Open vladfaust opened this issue 6 years ago • 1 comments

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.

vladfaust avatar Mar 01 '19 13:03 vladfaust

See https://github.com/vladfaust/callbacks.cr/issues/3.

vladfaust avatar May 01 '19 09:05 vladfaust