sinatra/sinatra — pull request #506 by snaggled (2012-04-26 01:22:51+00:00)
Title: Issue #467 Make #pass Behave as Expected in Error Blocks

With enable :show_exceptions (default), I would expect any exceptions to automatically be delegated to user-defined error blocks, in order. If the user-defined error block calls #pass, I'd expect the next error block to be invoked, and so on until finally, the default block (built-in Sinatra error handler) is invoked. This would enable you to do conditional handling of errors, such as returning a JSON formatted error when response.content_type is JSON, but falling through to the default error handling when HTML is expected.

Mainly 2 modifications:

1) I modified the error method to store an array of blocks specific to each key (e.g. http status code) instead of a single block
2) I modified the error_block! method to run through this array (backwards) until one of the blocks handles it.

You can thus add an error_handler and decide in that handler if you wish to 'pass'. The next error_handler in the chain will be called if you do so.

3 test cases included to demonstrate the desired functionality.