title: How to define global error handler for JSON in Sinatra
body: <p>I would like to define an error block (or something) that would return <strong>all</strong> exceptions formatted in JSON somehow <strong>plus</strong> returning the standard http code (e.g. 404 for not found, 303 for auth errors etc).</p>
  
  <p>Something like:</p>
  
  <pre><code>error do
    e = env['sinatra.error']
    json :result =&gt; 'error', :message =&gt; e.message
  end
  </code></pre>
  
  <p>Thanks!</p>