-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unhandled Rejection (Error): GraphQL error: Authentication required #6070
Comments
I'm having this issue where in development any graphql error get thrown and this CRA dialog shows up. I'm using apollo-link-error and I can see the errors get there but they're still raised. Any solution? |
same here |
same here |
not sure if this helps but i had a similar issue where throwing a IE This leads to an unhandled rejection error:
This works and allows me to grab the error from the mutation to display on the UI
|
@adildostmohamed it works... but is not a clean solution at all. I am implementing the HOC approach from Apollo, but so far, it doesn't works. I mean:
Also in the client, I can set up the error handler, but it doesn't avoid to broken sites...
The try/catch option propouse from @adildostmohamed :
works, but I dont think that is the best one. Any better solution?? |
@josuevalrob if you're trying to use the ie:
You should then be able to use your handleInvitation function as you had it before:
If you do this you shouldn't need to catch the error from the call to the mutate function if you're not fan of that. Alternatively if you don't want to use the onError prop on the Mutation component to specify the onError callback, you can use an alternative syntax to the try/catch scenario to something like:
Hopefully one of these approaches works for your needs |
I have a big application that sometimes does try to Easiest fix for us was to update the apolloClient configuration with export default new ApolloClient({
link,
cache,
defaultOptions: {
mutate: { errorPolicy: 'ignore' },
},
}); But the problem with this is that now the promises always resolve successfully, so the places that are using the |
Hi! Having the same issue here. I'm in a CRA TypeScript project using
My Apollo client const onErrorLink = onError(({ graphQLErrors, networkError }) => {
if (graphQLErrors)
graphQLErrors.map(({ message, locations, path }) =>
console.log(`[GraphQL error]: Message: ${message}, Location: ${locations}, Path: ${path}`)
);
if (networkError) console.log(`[Network error]: ${networkError}`);
}); When triggering an apollo error on a mutation that I have, my app crashes: Any idea of how to solve this? |
Same here |
same issue |
I'm getting the same issue as well. I'm using apollo-boost, which ships with apollo-client 2.6.8. I have tried errorPolicy: 'all' and errorPolicy: 'ignore' and I always get an unhandled promise exception. The only way around this is the hack of catching the error and sending it to console, But according to docs that's not how this is supposed to work. Using 'ignore' or 'all' is supposed to make errors that are sent from the server that are not network errors resolve, and simply update the error object. I have triple confirmed that my server is returning 200, and clearly GraphQL is classifying them at GraphQL errors, else our error would say something like Something is off here. Here is what my code looks like if it helps: const LOGIN = gql`
mutation Login($email: String!, $password: String!) {
login(password: $password, email: $email) {
token
}
}
`
export const Login = () => {
const [submitLogin, { data, error }] = useMutation<LoginResult, LoginArgs>(
LOGIN,
{ errorPolicy: 'all' },
)
const onSubmit = async (
_values: LoginFormValues,
_formik: FormikHelpers<LoginFormValues>,
) => {
submitLogin({
variables: {
email: _values.email,
password: _values.password,
},
})
}
const [submittedOnce, setSubmittedOnce] = useState(false)
const formik = useFormik<LoginFormValues>({
initialValues: { email: '', password: '' },
validateOnBlur: submittedOnce,
validateOnChange: submittedOnce,
onSubmit,
})
return (
...
)
} |
I have traced this down, at least in The |
Just updating... I upgraded my app to |
Just adding a callback on eg. <Mutation variables={state} onError={onError} mutation={CREATE_NEW_USER}> |
Hey guys! I had exactly the same problem. And solution was simple:
|
Hi guys, I'm having the same issue, I used which @ArtGurianov suggested, but it doesn't clear the store properly.. the user remains there after logout. |
If you are using the useMutation hook the following works: const [login, { loading, error }] = useMutation<
LoginMutation,
LoginMutationVariables
>(LOGIN, {
onCompleted({ login }) {
console.log("register :>> ", login, loading, error);
},
onError(error) {
console.error("error :>>", error.message);
},
}); |
Dealing with this for 2 hours wondering why my app constantly was crashing. Nothing about this in the official documentation, and no response from the maintainers. |
I was also having this issue. What I did in the end was to do a catch statement when invoking of tuple function. Here is my example using TypeScript and Apollo hooks:
After this implementation I no longer encountered the issue that the OP has. |
I have same issue ... and look like Apollo team don't care about fixing this! |
This temporarily helps me avoid the pain of using try, catch block. const [login, { data, loading, error }] = useLoginMutation({ onError: () => {} }); I hope to see the solution to this problem soon. Thanks for your hard work, Apollo team! |
Any progress on this? I'm having this issue with |
This is a nice solution if you're using the onError globally (ApolloClient), so you can catch all the API Errors on the onError method and the default error page of apollo will not appear and you will handle it |
Upgrading from 3.0.2 to 3.2.5 seems to have fixed this for me (without any |
@trevorr |
Can someone jump in explain whether this error handling behavior is a bug or by design? The same behavior happened in Apollo Client 2 (#3876), and since this hasn't been fixed yet, is this by design? If it is by design, it should be noted that the error handling behavior is inconsistent between useQuery and useMutation. |
Looks like there are no updates related to this issue... |
@johnnyoshika looks like it is not related to both useMutation and useQuery. Because now I use only useQuery and have the same issue. And it happens only after calling |
@pavelspichonak that's very interesting. I wonder if I'm having this issue because I'm resetting the store as well. |
I'm not resetting the store and I'm having this same problem on useMutation. |
Maybe it helps someone export const apolloClient = new ApolloClient({
uri: "http://localhost:8000/",
cache,
defaultOptions: {
mutate: { errorPolicy: "all" },
},
}); |
This should no longer be an issue in |
Can we get a little more information about the resolution here? Merely saying it's fixed doesn't actually solve the larger problem here. When we get unhandled errors we turn to issues such as this to find out why and what we can do to potentially fix the issue. Not everyone can be on the bleeding edge of the client. Also Is there a PR that we can reference that addresses this issue? Is there any background that we can use for us who can't yet update our package version on a whim? |
i still face the same problem
|
I'm using
When I use the hooks, I usually wrap them in a I fixed the issue and caught the unhandled error in my react app using the
Hope it helps someone. It's also a much better approach than |
I am using Otherwise, when I build my app and use it, the error is handled well and I don't have the "Unhandled Rejection" screen. The issue seems to be happening only when React is on development mode. |
this work for me thanks a lot!
|
same issue. setting |
Hey all 👋! Thanks for your patience. I see you're using If Any more information here would be helpful. Thanks! |
We're closing this issue now but feel free to ping the maintainers or open a new issue if you still need support. Thank you! |
Currently using the latest version of Having an ErrorLink Handler like this 6070# also doesn't work. Also, I'm not quite sure why would my useQueries still execute even though it is already unmounted. Perhaps that is the first reason why unhandled rejection occurs. |
@lfrallon Reading through this thread, I fear that these are a lot of very different problems that just piled up in this issue - some people report it is fixed, others don't. Could you please open a new issue for your case, and please include a reproduction? The issue template should point you to a few "reproduction starters", so you don't have to create one from scratch. |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Hi there,
I've been trying to implement authentication to a project of mine using apollo-client and apollo-server. It is really simple:
me
queryAuthenticationError
me
query, to update the client's cacheclient.resetStore
me
query againAuthenticationError
Looking at the dev tools, everything looks fine.
At page load, the user is not logged in. The
me
query returns null (and anAuthenticationError
error)After login, I get data from the
me
queryFinally, after logout, the
me
query returns again null (and anAuthenticationError
error)But this time my client app breaks with this error
I find this a bit weird because the cache at page load and after logout is the same (empty cache). And the server responses are identical, yet the client behaves differently.
My implementation is pretty similar to the one described in the official documentation (using cookies).
Does anybody have an idea why this happens?
The text was updated successfully, but these errors were encountered: