Skip to content

Commit

Permalink
feat(http-client): Expose HttpClient to interceptors
Browse files Browse the repository at this point in the history
  • Loading branch information
davismj committed Apr 28, 2018
1 parent 946273a commit 36518bc
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/http-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export class HttpClient {
this::trackRequestStart();

let request = Promise.resolve().then(() => this::buildRequest(input, init, this.defaults));
let promise = processRequest(request, this.interceptors)
let promise = processRequest(request, this.interceptors, this)
.then(result => {
let response = null;

Expand All @@ -118,7 +118,7 @@ export class HttpClient {
throw new Error(`An invalid result was returned by the interceptor chain. Expected a Request or Response instance, but got [${result}]`);
}

return request.then(_request => processResponse(response, this.interceptors, _request));
return request.then(_request => processResponse(response, this.interceptors, _request, this));
});

return this::trackRequestEndWith(promise);
Expand Down Expand Up @@ -201,12 +201,12 @@ function setDefaultHeaders(headers, defaultHeaders) {
}
}

function processRequest(request, interceptors) {
return applyInterceptors(request, interceptors, 'request', 'requestError');
function processRequest(request, interceptors, http) {
return applyInterceptors(request, interceptors, 'request', 'requestError', http);
}

function processResponse(response, interceptors, request) {
return applyInterceptors(response, interceptors, 'response', 'responseError', request);
function processResponse(response, interceptors, request, http) {
return applyInterceptors(response, interceptors, 'response', 'responseError', request, http);
}

function applyInterceptors(input, interceptors, successName, errorName, ...interceptorArgs) {
Expand Down

0 comments on commit 36518bc

Please sign in to comment.