Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation
This project
Loading...
Sign in
hfpp2012
/
merng
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 73924ec4
authored
Nov 22, 2019
by
qiuzhi99
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
error-handler
1 parent
4c47e536
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
19 additions
and
2 deletions
client/package.json
client/src/ApolloProvider.js
client/yarn.lock
client/package.json
View file @
73924ec
...
...
@@ -7,6 +7,7 @@
"apollo-boost"
:
"^0.4.4"
,
"apollo-cache-inmemory"
:
"^1.6.3"
,
"apollo-link-context"
:
"^1.0.19"
,
"apollo-link-error"
:
"^1.1.12"
,
"apollo-link-http"
:
"^1.5.16"
,
"graphql"
:
"^14.5.8"
,
"graphql-tag"
:
"^2.10.1"
,
...
...
client/src/ApolloProvider.js
View file @
73924ec
...
...
@@ -5,6 +5,7 @@ import { ApolloProvider } from "@apollo/react-hooks";
import
{
createHttpLink
}
from
"apollo-link-http"
;
import
{
InMemoryCache
}
from
"apollo-cache-inmemory"
;
import
{
setContext
}
from
"apollo-link-context"
;
import
{
onError
}
from
"apollo-link-error"
;
const
httpLink
=
createHttpLink
({
uri
:
"http://localhost:5001"
});
...
...
@@ -17,8 +18,23 @@ const authLink = setContext(() => {
};
});
const
errorLink
=
onError
(({
graphQLErrors
,
operation
,
forward
})
=>
{
if
(
graphQLErrors
)
{
for
(
let
err
of
graphQLErrors
)
{
switch
(
err
.
extensions
.
code
)
{
case
"UNAUTHENTICATED"
:
window
.
location
.
href
=
"/login"
;
// retry the request, returning the new observable
return
forward
(
operation
);
}
}
}
});
const
link
=
errorLink
.
concat
(
authLink
);
const
client
=
new
ApolloClient
({
link
:
authL
ink
.
concat
(
httpLink
),
link
:
l
ink
.
concat
(
httpLink
),
cache
:
new
InMemoryCache
()
});
...
...
client/yarn.lock
View file @
73924ec
...
...
@@ -1797,7 +1797,7 @@ apollo-link-context@^1.0.19:
apollo-link "^1.2.13"
tslib "^1.9.3"
apollo-link-error@^1.0.3:
apollo-link-error@^1.0.3
, apollo-link-error@^1.1.12
:
version "1.1.12"
resolved "https://registry.npm.taobao.org/apollo-link-error/download/apollo-link-error-1.1.12.tgz#e24487bb3c30af0654047611cda87038afbacbf9"
integrity sha1-4kSHuzwwrwZUBHYRzahwOK+6y/k=
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment