Fix json parsing exceptions obscuring server errors (#1605)

I got a 413 (Rate limit exceeded) error from the server while fetching prekeys.
The client tried to parse the response as json since we expect json from the
prekey endpoint, which threw an exception because the response was not json.
This change prevents us from treating the response as json unless it has the
Content-Type header set accordingly.

If for some reason, the client and server disagree on whether the response
should be or is json, we'll default to treating it as text.

// FREEBIE
pull/749/head
Lilia 8 years ago committed by Scott Nonnenberg
parent 1a2b123f31
commit d1f7f5ee8c

@ -37501,12 +37501,13 @@ var TextSecureServer = (function() {
}
window.nodeFetch(url, fetchOptions).then(function(response) {
var resultPromise;
if (options.responseType === 'json') {
if (options.responseType === 'json'
&& response.headers.get('Content-Type') === 'application/json') {
resultPromise = response.json();
} else if (!options.responseType || options.responseType === 'text') {
resultPromise = response.text();
} else if (options.responseType === 'arraybuffer') {
resultPromise = response.buffer();
} else {
resultPromise = response.text();
}
return resultPromise.then(function(result) {
if (options.responseType === 'arraybuffer') {

@ -64,12 +64,13 @@ var TextSecureServer = (function() {
}
window.nodeFetch(url, fetchOptions).then(function(response) {
var resultPromise;
if (options.responseType === 'json') {
if (options.responseType === 'json'
&& response.headers.get('Content-Type') === 'application/json') {
resultPromise = response.json();
} else if (!options.responseType || options.responseType === 'text') {
resultPromise = response.text();
} else if (options.responseType === 'arraybuffer') {
resultPromise = response.buffer();
} else {
resultPromise = response.text();
}
return resultPromise.then(function(result) {
if (options.responseType === 'arraybuffer') {

Loading…
Cancel
Save