Commit 4128c738 authored by Robert Knight's avatar Robert Knight

Use ES6 destructuring to tidy up a Promise `then` callback

parent be56b227
...@@ -137,15 +137,13 @@ function createAPICall($http, $q, links, route, tokenGetter) { ...@@ -137,15 +137,13 @@ function createAPICall($http, $q, links, route, tokenGetter) {
// `$q.all` is used here rather than `Promise.all` because testing code that // `$q.all` is used here rather than `Promise.all` because testing code that
// mixes native Promises with the `$q` promises returned by `$http` // mixes native Promises with the `$q` promises returned by `$http`
// functions gets awkward in tests. // functions gets awkward in tests.
var token; var accessToken;
return $q.all([links, tokenGetter()]).then(function (linksAndToken) { return $q.all([links, tokenGetter()]).then(([links, token]) => {
var links = linksAndToken[0];
token = linksAndToken[1];
var descriptor = get(links, route); var descriptor = get(links, route);
var url = urlUtil.replaceURLParams(descriptor.url, params); var url = urlUtil.replaceURLParams(descriptor.url, params);
var headers = {}; var headers = {};
accessToken = token;
if (token) { if (token) {
headers.Authorization = 'Bearer ' + token; headers.Authorization = 'Bearer ' + token;
} }
...@@ -161,7 +159,7 @@ function createAPICall($http, $q, links, route, tokenGetter) { ...@@ -161,7 +159,7 @@ function createAPICall($http, $q, links, route, tokenGetter) {
return $http(req); return $http(req);
}).then(function (response) { }).then(function (response) {
if (options.includeMetadata) { if (options.includeMetadata) {
return { data: response.data, token }; return { data: response.data, token: accessToken };
} else { } else {
return response.data; return response.data;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment