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

Cancel axios requests when newer axios requests are sent #293

Open
JobDoesburg opened this issue May 3, 2022 · 0 comments
Open

Cancel axios requests when newer axios requests are sent #293

JobDoesburg opened this issue May 3, 2022 · 0 comments

Comments

@JobDoesburg
Copy link
Collaborator

Currently, the updateOrder method in the salesService looks as follows:

  async updateOrder(order: Order, shift: number | null = null): Promise<Order> {
    if (order._o === null && shift !== null) {
      order = await this.newOrder(shift, order);
      return order;
    }
    const result: AxiosResponse<_Order> = await this.apiService.put(
      // eslint-disable-next-line @typescript-eslint/ban-ts-comment
      // @ts-ignore
      `/admin/sales/orders/${order._o.pk}/`,
      // eslint-disable-next-line @typescript-eslint/ban-types
      order.getAPIData() as {}
    );
    order.updateFromAPI(result.data);
    return order;
  }

When there is a bad network, it can be possible that a new request is sent to the apiService while the old one has not yet been finished. This can result in orders suddenly changing. We should prevent such behavior and cancel the order.updateFromAPI(result.data); line when a newer request has been sent. So on sending an update, cancel any previous update.

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

No branches or pull requests

1 participant