Skip to content
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

Unable to access to entire Error object on tanstack/query response #1488

Closed
vitorcamachoo opened this issue Dec 30, 2024 · 2 comments
Closed

Comments

@vitorcamachoo
Copy link

vitorcamachoo commented Dec 30, 2024

What is the problem this feature would solve?

Kubb configuration allows to specification of the data return type for the success case, but in our case, for errors, we want to be able to access the entire Error Object, in this case, the AxiosError.
Right now we are using Orval, and their approach to accomplish this is to create a custom interface in the custom client file and that type will be used in the generated file, similar to what you suggest when creating the RequestConfig.

That said, our goal was to have something configurable in the custom client instead of the kubb configuration file, like the following:

export type RequestConfig<TData = unknown> = AxiosRequestConfig<TData>;
export type ResponseConfig<TData = unknown> = AxiosResponse<TData>;
export type ResponseErrorConfig<TError = unknown> = AxiosError<TError>;

export const customInstance = <TData, TError = unknown, TVariables = unknown>(
  config: RequestConfig<TVariables>
): Promise<ResponseConfig<TData>['data']> => {
  return instance
    .request<TVariables, ResponseConfig<TData>>(config)
    .then(({ data }) => data)
    .catch((e: ResponseErrorConfig<TError>) => {
      throw e;
    });
};

export default customInstance;

External documents/projects?

No response

What is the feature you are proposing to solve the problem?

No response

What alternatives have you considered?

No response

@stijnvanhulle
Copy link
Collaborator

This has been added with version v3.4.0 🎉

@vitorcamachoo
Copy link
Author

This has been added with version v3.4.0 🎉

Is there any documentation on how to achieve that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants