Skip to content

Ability to return a new response from onResponseError #160

@maksimdrosdov

Description

@maksimdrosdov

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
      });
    }
  });

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions