Moved error handling code out into client/lib.