Skip to content

Commit

Permalink
fix(service): Now callbacks would be called only if the handler has i…
Browse files Browse the repository at this point in the history
…mplemented it
  • Loading branch information
thekalinga committed Feb 2, 2017
1 parent ec51115 commit 8919e44
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/interceptor-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,8 @@ export class InterceptorService extends Http {

for (let index = startFrom; index >= 0; index--) {
const interceptor: Interceptor = this.interceptors[index];
if (interceptor.onResponse === undefined) {

if (!interceptor.onResponse && !interceptor.onShortCircuit && !interceptor.onErr && !interceptor.onForceCompleteOrForceReturn) {
continue;
}

Expand All @@ -311,10 +312,14 @@ export class InterceptorService extends Http {
let processedResponse: void | InterceptorResponseWrapper | Observable<InterceptorResponseWrapper>;

if (transformedResponseWrapper.err) {
processedResponse = interceptor.onErr(transformedResponseWrapper, index);
if (interceptor.onErr !== undefined) {
processedResponse = interceptor.onErr(transformedResponseWrapper, index);
}
} else if (transformedResponseWrapper.isShortCircuited()) {
processedResponse = interceptor.onShortCircuit(transformedResponseWrapper, index);
} else {
if (interceptor.onShortCircuit !== undefined) {
processedResponse = interceptor.onShortCircuit(transformedResponseWrapper, index);
}
} else if (interceptor.onResponse !== undefined) {
processedResponse = interceptor.onResponse(transformedResponseWrapper, index);
}

Expand Down

0 comments on commit 8919e44

Please sign in to comment.