Add exception handling to HttpMiddleware