-
-
Notifications
You must be signed in to change notification settings - Fork 45
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
isErrorFromAlias not finding errors when uri have undefined params #402
Comments
it's checking the uri, because that's all the error that got rejected has to provide to match the call. The alias alone can't allow to match the error uri. In v11, i'am now evaluating to remove this entirely and make the call return the object error, like this : const { data: user, error } = client.getUser(); instead of : try {
const user = client.getUser();
} catch (e) {
if(isErrorFromAlias('getUser')) {
...
}
} But the decision to do this breaking change is not yet settled |
Yes but you could use the alias to get the endpoint (like you did) and only the status for the error ; const endpoint = findEndpointByAlias(api, alias);
return (endpoint &&
err.config &&
endpoint.method === err.config.method)
? findEndpointErrors(endpoint, err)
: undefined; Also you probably should add ( ) around the condition, it's more readable and typescript don't complain that way |
I'm using https://github.com/causaly/zod-validation-error for better errors: if(err instanceof ZodiosError) {
if (err.cause instanceof ZodError) {
console.log(fromZodError(err.cause).toString())
}
} |
Hello,
TLDR;
isErrorFromAlias
is checking theisErrorFromPath
does.I have an issue where, now I can fix easily but what really hard to debug.
I was using
isErrorFromAlias
but was returning false and I was not able to figure out why. I tried using a z.any() schema, an 'default' status but none of them worked.After copying the code of
isErrorFromAlias
in my project and add many many console.log I was able to find the issue.It's related to this code :
zodios/src/utils.ts
Lines 111 to 125 in e8232fc
Even it's looking for the endpoint using the alias it's still checking the uri.
The issue is in the
pathMatchesUrl
method ;zodios/src/utils.ts
Lines 127 to 130 in e8232fc
But in my case the endpoint URI is
/api/:apiKey/config/whitelist/:oldApiKey
and the url of the Axios response is/api/SOME_KEY/config/whitelist/
The regex is resolved to
/api/([^/]+)/config/whitelist/([^/]+)
but that don't match the response url because oldApiKey was undefined.The easy fix it to make sure the oldApiKey is defined.
My question, if it's looking with the alias why it's still checking the uri ?
And a side question, does the alias need to be uniques in the api ?
Thanks
The text was updated successfully, but these errors were encountered: