-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
Description
Is your feature request related to a problem? Please describe.
There is currently no way to cancel requests in the generated service calls for both Axios and Fetch generators (..that I know of, sorry if this is not true).
Describe the solution you'd like
A way to enable an option to have a cancel token added to the request and ideally be able to reference this cancel token after the request has been made (i.e. return the cancel token somehow).
Describe alternatives you've considered
Currently we have a generic service layer that does this:
export function get<T>(url: string, { params }: any = {}): CancelableAxiosPromise<T> {
const source = axios.CancelToken.source();
const axiosRequest: any = axios.get(url, { params, cancelToken: source.token });
const request: CancelableAxiosPromise<T> = axiosRequest.catch(handleError);
request[CANCEL] = () => source.cancel(); //Redux-Saga cancel property on request
return request;
}
Redux-Saga needs the CANCEL property on the request to be able to automatically cancel when using TakeLatest. We use this CANCEL property outside of redux-saga as well if we need to cancel a request.
Additional context
I am open to changing the way we have the cancellation implemented, any suggestions are welcome if I am overcomplicating this. Just trying to piece together how we can take advantage of Codegen since we will be switching to using OpenApi exclusively.