Added a middleware that automatically calls a handler function when a panic occurs in a request.