Error checking should be done before Response checking

When there is an error then response object can be `nil`. We should check errors before we do any operation on response object.