Better error handling by checking response type.