Extract exception handling into a middleware

Rescue exceptions that are raised and set the response. If the exception
rescued is not a Protobuf error, it is wrapped in a generic Protobuf
error.