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

Ability to return a new response from onResponseError #160

Open
maksimdrosdov opened this issue Nov 12, 2022 · 8 comments
Open

Ability to return a new response from onResponseError #160

maksimdrosdov opened this issue Nov 12, 2022 · 8 comments
Labels
enhancement New feature or request

Comments

@maksimdrosdov
Copy link

maksimdrosdov commented Nov 12, 2022

hello, on submit, if the tokens are valid, everything works correctly and Swal displays a message, if the token is not valid, a refresh fires, the form submit fires again, but Swal no longer displays a message. How to deal with it?

 async onResponseError(ctx: FetchContext): Promise<any> {
    if (ctx.response.status === 401) {
      const { error } = await this.refreshToken();

      if (!error) {
        // eslint-disable-next-line no-return-await
        return await this.fetcher(ctx.request, ctx.options);
      }
    }
  }

repository

async addProductToCart(body: any, filter: any = {}): Promise<any> {
    return this.fetcher(this.urlGenerator.addProductToCart(), {
      method: 'POST',
      body,
      params: filter
    });
  }

my function

const onSubmit = handleSubmit(async () => {
    const {
      error,
      pending
    } = await useLazyAsyncData(
      'updateUserProfile',
      () => httpRepository.addProductToCart(form),
      {
        initialCache: false
      }
    );

    isLoading.value = pending.value;

    if (!error.value) {
      Swal.fire({
        toast: true,
        position: 'top-right',
        text: 'Данные успешно обновлены!',
        icon: 'success',
        timer: 3000,
        showConfirmButton: false
      });
    }
  });
@nozomuikuta
Copy link
Member

I feel this issue is potentially related to and/or duplicated of #114.
But, we appreciate if you provide a minimal reproduction by which everyone can see what you see.

@linshujuan
Copy link

@maksimdrosdov Hi, do you solve this issue, I also meeting this problem right now

@TusharRoy23
Copy link

Any update on that?

@dselivanovvv
Copy link

hey, did u solve the issue?

Copy link
Member

atinux commented Sep 6, 2023

I believe this is related to the fact that we don't look at what onResponseError can return:

await context.options.onResponseError(context as any);

This means that we ignore what you can return.

I think we should change the behavior in order to transform the response based on it, similar to Axios.

@atinux atinux changed the title onResponseError Ability to return a new response from onResponseError Sep 6, 2023
@atinux atinux added enhancement New feature or request and removed needs reproduction labels Sep 6, 2023 — with Volta.net
@trandaison
Copy link

I believe this issue is same as #224.

Have you tried to modify the context.response in onResponseError yet? It should work.

#224 (comment)

@cgnz0r
Copy link

cgnz0r commented Dec 18, 2023

I tried to modify the context.response in onResponseError - It doesn't work for me, I get the same result as when there is no onResponseError handler.

nuxt 3.8.2 Still facing this problem :(

@trandaison
Copy link

@cgnz0r Can you create a codesandbox to reproduce the issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

8 participants