Fix retry
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { execute, makePromise, ApolloLink } from 'apollo-link';
|
import { execute, makePromise, ApolloLink, Observable } from 'apollo-link';
|
||||||
import { HttpLink } from 'apollo-link-http';
|
import { HttpLink } from 'apollo-link-http';
|
||||||
import gql from 'graphql-tag';
|
import gql from 'graphql-tag';
|
||||||
const { includeCredentials } = require('./middleware');
|
const { includeCredentials } = require('./middleware');
|
||||||
@@ -22,10 +22,20 @@ const errorLink = onError(({ graphQLErrors, networkError, operation, forward })
|
|||||||
}
|
}
|
||||||
if (networkError) {
|
if (networkError) {
|
||||||
if (networkError.statusCode === 401) {
|
if (networkError.statusCode === 401) {
|
||||||
webAuth.checkSession(() => {
|
return new Observable(observer => {
|
||||||
return forward(operation);
|
webAuth.checkSession(() => {
|
||||||
}, (err) => {
|
const subscriber = {
|
||||||
console.log(err);
|
next: observer.next.bind(observer),
|
||||||
|
error: observer.error.bind(observer),
|
||||||
|
complete: observer.complete.bind(observer)
|
||||||
|
};
|
||||||
|
|
||||||
|
// Retry last failed request
|
||||||
|
forward(operation).subscribe(subscriber);
|
||||||
|
}, (err) => {
|
||||||
|
console.log(err);
|
||||||
|
observer.error(err)
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user