Override Sinatra default NotFound error page

后端 未结 3 1320
后悔当初
后悔当初 2021-02-05 20:17

Is there a way to override the sinatra default NotFound error page (\"Sinatra doesnt know this ditty\")? I want sinatra to show only a plain string as \"Method not found\" when

3条回答
  •  失恋的感觉
    2021-02-05 21:06

    Perhaps a more graceful solution than that proposed in the accepted answer is to rescue only Sinatra::NotFound, rather than using the error(404) or not_found styles.

    error Sinatra::NotFound do
      content_type 'text/plain'
      [404, 'Not Found']
    end
    

    This prevents the "sinatra doesn't know this ditty" default page for routes that you haven't defined, but doesn't get in the way of explicit return [404, 'Something else']-style responses.

提交回复
热议问题