Restructure error checking to avoid reporting bogus error.

As Zell pointed out, getError() returns the current error and clears it. So
calling it twice resulted in bogosity.