Improved error handling.

Issue: GCP-9122
Reviewer: Rebecca (post commit)