Skip to content

Commit

Permalink
Fixes duplication of code.
Browse files Browse the repository at this point in the history
  • Loading branch information
thehappybug committed Oct 27, 2023
1 parent e15105e commit fb6653c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
8 changes: 4 additions & 4 deletions packages/core-interfaces/src/httpInterceptor.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { HttpRequest, RequestOptions } from './httpRequest';
import { HttpRequest } from './httpRequest';
import { HttpContext } from './httpContext';

/**
Expand Down Expand Up @@ -41,9 +41,9 @@ export function passThroughInterceptor<T>(
/**
* Combine multiple HTTP interceptors into one.
*/
export function combineHttpInterceptors(
interceptors: Array<HttpInterceptorInterface<RequestOptions | undefined>>
): HttpInterceptorInterface<RequestOptions | undefined> {
export function combineHttpInterceptors<T>(
interceptors: Array<HttpInterceptorInterface<T | undefined>>
): HttpInterceptorInterface<T | undefined> {
return (firstRequest, firstOptions, next) => {
for (let index = interceptors.length - 1; index >= 0; index--) {
const current = interceptors[index];
Expand Down
10 changes: 3 additions & 7 deletions packages/core/src/http/httpInterceptor.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
HttpInterceptorInterface,
HttpCallExecutor,
combineHttpInterceptors,
} from '@apimatic/core-interfaces';
/**
* Calls HTTP interceptor chain
Expand All @@ -12,11 +13,6 @@ export function callHttpInterceptors<T>(
interceptors: Array<HttpInterceptorInterface<T>>,
client: HttpCallExecutor<T>
): HttpCallExecutor<T> {
let next = client;
for (let index = interceptors.length - 1; index >= 0; index--) {
const current = interceptors[index];
const last = next;
next = (request, options) => current(request, options, last);
}
return next;
return (request, options) =>
combineHttpInterceptors(interceptors)(request, options, client);
}

0 comments on commit fb6653c

Please sign in to comment.