Skip to content

Commit 6f3dc44

Browse files
dmitryAkryum
andauthored
fix: check errors.length on array (#984)
* fix: check errors.length on array * fix(lint): error Co-authored-by: Guillaume Chau <[email protected]>
1 parent 98bc132 commit 6f3dc44

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

packages/vue-apollo/src/smart-query.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,9 @@ export default class SmartQuery extends SmartApollo {
143143

144144
const { data, loading, error, errors } = result
145145

146-
if (error || errors) {
146+
const anyErrors = errors && errors.length
147+
148+
if (error || anyErrors) {
147149
this.firstRunReject()
148150
}
149151

@@ -154,7 +156,7 @@ export default class SmartQuery extends SmartApollo {
154156
// If `errorPolicy` is set to `all`, an error won't be thrown
155157
// Instead result will have an `errors` array of GraphQL Errors
156158
// so we need to reconstruct an error object similar to the normal one
157-
if (errors && errors.length) {
159+
if (anyErrors) {
158160
const e = new Error(`GraphQL error: ${errors.map(e => e.message).join(' | ')}`)
159161
Object.assign(e, {
160162
graphQLErrors: errors,
@@ -165,7 +167,7 @@ export default class SmartQuery extends SmartApollo {
165167
super.catchError(e)
166168
}
167169

168-
if (this.observer.options.errorPolicy === 'none' && (error || errors)) {
170+
if (this.observer.options.errorPolicy === 'none' && (error || anyErrors)) {
169171
// Don't apply result
170172
return
171173
}

0 commit comments

Comments
 (0)