Skip to content

Custom fail method #3

@mull

Description

@mull

Hey. First of all I dig the gem, loving how simple it is. Not sure if it was intended for my type of use though. I'm building an API which requires authentication for certain requests, but a simple redirect to '/whatever_route' isn't quite what one would expect when developing against an API and authentication fails.

Maybe I'm just lacking the necessary Sinatra skills (yes I am new at this), but something like

def authentication_required
  status 403
  {"error" => "Authentication required."}.to_json
end

set :session_fail, lambda { authentication_required }

would be awesome. Of course the "authentication_required" method fails here as it doesn't have the status method. Any way to accomplish this? Would love to send a PR with documentation if you can help me figure this out. Cheers! :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions