halt from before hook

13 views
Skip to first unread message

abhijit nandy

unread,
Sep 2, 2021, 2:06:27 AM9/2/21
to Roda
Hi,

I have included the hook and halt plugins.

I want to be able to halt a request with a status code on some condition.

For example -

before do
  unless @user
    response.status = 401
    # halt processing and return from here
    # something like this
    # return { :error => 'Invalid User'}
  end
end

Any suggestions as to how I can achieve this?

Thanks,
 - Abhijit.

abhijit nandy

unread,
Sep 2, 2021, 3:26:52 AM9/2/21
to Roda
Hi,

I managed to solve it with -

before do
  request.halt(401, 'Invalid User') unless @user
end
Reply all
Reply to author
Forward
0 new messages