Skip to content

Cancel axios requests when newer axios requests are sent #293

@JobDoesburg

Description

@JobDoesburg

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions