@@ -352,10 +352,18 @@ export class {{classname}} {
352352 this.configuration.beforeHandler(' {{operationIdOriginal}}' , ' {{httpMethod}}' .toUpperCase());
353353 }
354354 if (typeof this.configuration.afterHandler === 'function') {
355- handle = handle.pipe(tap(
356- result => this.configuration.afterHandler(' {{operationIdOriginal}}' , ' {{httpMethod}}' .toUpperCase(), result),
357- err => this.configuration.afterHandler(' {{operationIdOriginal}}' , ' {{httpMethod}}' .toUpperCase(), err)
358- ));
355+ const afterHandler = (result: any, stopCancellation = true ) => {
356+ if (stopCancellation && cancelPreviousRequest && this.cancelMap[' {{operationIdOriginal}}' ]) {
357+ // don' t call next to prevent second call
358+ this.cancelMap[' {{operationIdOriginal} }'].complete();
359+ this.cancelMap['{ {operationIdOriginal} }'] = null;
360+ }
361+ this.configuration.afterHandler('{ {operationIdOriginal} }', '{ {httpMethod} }'.toUpperCase(), result);
362+ };
363+ handle = handle.pipe(tap(afterHandler, afterHandler)));
364+ if (cancelPreviousRequest && this.cancelMap['{ {operationIdOriginal} }']) {
365+ this.cancelMap[' {{operationIdOriginal}}' ].asObservable().subscribe(() => afterHandler(new Error(' CANCELLED' ), false ));
366+ }
359367 }
360368
361369 if (typeof this.configuration.errorHandler === 'function') {
@@ -404,10 +412,18 @@ export class {{classname}} {
404412 this.configuration.beforeHandler(' {{operationIdOriginal}}' , ' {{httpMethod}}' .toUpperCase());
405413 }
406414 if (typeof this.configuration.afterHandler === 'function') {
407- handle = handle.tap(
408- result => this.configuration.afterHandler(' {{operationIdOriginal}}' , ' {{httpMethod}}' .toUpperCase(), result),
409- err => this.configuration.afterHandler(' {{operationIdOriginal}}' , ' {{httpMethod}}' .toUpperCase(), err)
410- );
415+ const afterHandler = (result: any, stopCancellation = true ) => {
416+ if (stopCancellation && cancelPreviousRequest && this.cancelMap[' {{operationIdOriginal}}' ]) {
417+ // don' t call next to prevent second call
418+ this.cancelMap[' {{operationIdOriginal} }'].complete();
419+ this.cancelMap['{ {operationIdOriginal} }'] = null;
420+ }
421+ this.configuration.afterHandler('{ {operationIdOriginal} }', '{ {httpMethod} }'.toUpperCase(), result);
422+ };
423+ handle = handle.tap(afterHandler, afterHandler);
424+ if (cancelPreviousRequest && this.cancelMap['{ {operationIdOriginal} }']) {
425+ this.cancelMap[' {{operationIdOriginal}}' ].asObservable().subscribe(() => afterHandler(new Error(' CANCELLED' ), false ));
426+ }
411427 }
412428
413429 if (typeof this.configuration.errorHandler === 'function') {
0 commit comments