mst-gql
mst-gql copied to clipboard
Error cannot be caught: "onrejected is not a function"
Hi, I got an porblem while running the example 3, I purposely add throw new Error()
to one of the server's resolvers and then the client seems to unable to handle the error properley.
const { data, error } = useQuery(...)
error
above will return undefined, and if I try to use then().catch()
to catch the error, the error message will be 'onrejected is not a function'. I haven't read all the codes yet, but it seems the error happens here: https://github.com/mobxjs/mst-gql/blob/master/src/MSTGQLStore.ts#L147
@tylerstar Hi this is kind of a bug, to catch the error you have to do it like so here:
https://github.com/mobxjs/mst-gql/blob/90c786e5646ee4a4619ffb9e85e272c2b84e730d/src/Query.ts#L170
so it becomes
.then(data => ondata(data), error => onerror(error))
but anyway we should check if the user provides that function