title: How do I configure Sinatra to serve 403 (Forbidden) on a specific exception?
body: <p>Currently, I have something like this:</p>
  
  <pre><code>def valid?(stuff)
    #...
  end
  
  get '/somewhere'
    return status 403 unless valid?(something) &amp;&amp; valid?(something_else)
    # ...
  end
  </code></pre>
  
  <p>(In this specific case, I am checking whether a <code>param</code> containing a file name is inside the directory allowed for that parameter, to prevent users from accessing what they shouldn't.)</p>
  
  <p>But it gets unwieldy, especially since I have the same structure in multiple places. I'd rather do something like this:</p>
  
  <pre><code>def ensure_valid(stuff)
    raise Forbidden unless valid?(stuff)
  end
  
  get '/somewhere'
    ensure_valid(something)
    ensure_valid(something_else)
    # ...
  end
  </code></pre>
  
  <p>Is there such an exception? If not, how can I configure Sinatra (or Rack, for that matter) to abort the request with <code>status 403</code> if it catches a custom exception?</p>