Skip to content

Commit

Permalink
fix: check errors.length on array (#984)
Browse files Browse the repository at this point in the history
* fix: check errors.length on array

* fix(lint): error

Co-authored-by: Guillaume Chau <[email protected]>
  • Loading branch information
dmitry and Akryum authored Jul 27, 2020
1 parent 98bc132 commit 6f3dc44
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions packages/vue-apollo/src/smart-query.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,9 @@ export default class SmartQuery extends SmartApollo {

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

if (error || errors) {
const anyErrors = errors && errors.length

if (error || anyErrors) {
this.firstRunReject()
}

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

if (this.observer.options.errorPolicy === 'none' && (error || errors)) {
if (this.observer.options.errorPolicy === 'none' && (error || anyErrors)) {
// Don't apply result
return
}
Expand Down

0 comments on commit 6f3dc44

Please sign in to comment.