sinatra-respond_to
sinatra-respond_to copied to clipboard
Handle invalid formats
When someone requests a completely invalid format like .jon the gem raises a RuntimeError:
2013-09-26T13:39:57.276957500+0000 Command :: file -b --mime '/tmp/RackMultipart20130926-21117-1z02por'
2013-09-26T15:39:13.182194500+0000 RuntimeError - Unknown media type jon
2013-09-26T15:39:13.191164500+0000 Try registering the extension with a mime type:
2013-09-26T15:39:13.191193500+0000 /data/a/app/shared/bundle/ruby/1.9.1/bundler/gems/sinatra-respond_to-99567f110d71/lib/sinatra/respond_to.rb:172:in `format'
2013-09-26T15:39:13.191206500+0000 /data/a/app/shared/bundle/ruby/1.9.1/bundler/gems/sinatra-respond_to-99567f110d71/lib/sinatra/respond_to.rb:57:in `block in registered'
2013-09-26T15:39:13.191218500+0000 /data/a/app/shared/bundle/ruby/1.9.1/gems/sinatra-1.4.3/lib/sinatra/base.rb:1541:in `call'
It'd like to return a HTTP 406 in this instance and don't want to rescue globally from a RuntimeError. What's the best way to do this?
Thanks!