Replies: 1 comment
-
Unfortunately I can't give you much advice here - I'm not aware of any specification for GraphQL errors, beyond what fields should be present. It's more or less up to the author of the GraphQL server to decide what goes into errors.
Error messages can appear at any index. An error like "access token not found" is moderately likely to be the 1st and only message, just because I'd expect it to be validated first and execution to stop - meaning there's no where else for errors to come from. But that depends on the server - there's no guarantee.
The latter is definitely the safer option - but as I've said, it depends on the server. The first one might actually be fine in a lot of cases.
Yeah, unfortunately checking the message is the best option here. GraphQL errors aren't designed in a particularly machine friendly manner - they are mostly just arbitrary strings for a human to read, so it'd be difficult for a library to handle them correctly. There is the extensions field that server authors can sometimes use to pass structured data back (e.g. an error code for unauthorized) but I've very rarely seen a server actually do that. |
Beta Was this translation helpful? Give feedback.
-
Hello,
I would like to know how to extract the error message 'Access token not found' from a response. Are error messages typically found in the first index of an 'errors' array? Is it considered safe to hardcode the index like
&response.errors.unwrap()[0].message
? Or is it better practice to collect all the errors and check if 'Access token not found.' exists in one of the vector elements?Additionally, how can I ensure that the error response matches our expected error message 'Access token not found' rather than something like 'internal error'? Is this typically done manually by checking the error message, or are there Rust types or libraries that can assist with this validation?
I think getting an error message should be in the examples.
cynic/examples/examples/chrono-scalars.rs
Line 73 in 63b105d
cynic/examples/examples/github-mutation.rs
Line 110 in 63b105d
Beta Was this translation helpful? Give feedback.
All reactions