mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 07:07:35 +01:00
switch to standard response format in v3
This commit is contained in:
@@ -61,7 +61,7 @@ function _requestMaker (user, method, additionalSets = {}) {
|
||||
|
||||
let parsedError = _parseError(err);
|
||||
|
||||
reject(parsedError);
|
||||
return reject(parsedError);
|
||||
}
|
||||
|
||||
// if any cookies was sent, save it for the next request
|
||||
@@ -71,13 +71,31 @@ function _requestMaker (user, method, additionalSets = {}) {
|
||||
}).join('; ');
|
||||
}
|
||||
|
||||
let contentType = response.headers['content-type'] || '';
|
||||
resolve(contentType.indexOf('json') !== -1 ? response.body : response.text);
|
||||
resolve(_parseRes(response));
|
||||
});
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
function _parseRes (res) {
|
||||
let contentType = res.headers['content-type'] || '';
|
||||
let contentDisposition = res.headers['content-disposition'] || '';
|
||||
|
||||
if (contentType.indexOf('json') === -1) { // not a json response
|
||||
return res.text;
|
||||
}
|
||||
|
||||
if (contentDisposition.indexOf('attachment') !== -1) {
|
||||
return res.body;
|
||||
}
|
||||
|
||||
if (apiVersion === 'v2') {
|
||||
return res.body;
|
||||
} else if (apiVersion === 'v3') {
|
||||
return res.body.data;
|
||||
}
|
||||
}
|
||||
|
||||
function _parseError (err) {
|
||||
let parsedError;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user