Factor out error type checks