Inspect the errors, not the string

Replaces the previous ugly string-comparison hack.