Skip to content

Commit e1115d2

Browse files
committed
fix default case for responseType in WireClient._fetchRequest #1151
If no responseType property is present in options parameter to WireClient._fetchRequest, the function defaults to document and throws an error. If responseType is undefined, the function should treat the response as text. Also, if the response is treated as text, the syntheticXhr.responseText property should be set to processedBody in order to not break XHR compatibility.
1 parent 725269d commit e1115d2

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/wireclient.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,7 @@ WireClient._fetchRequest = function (method, url, options) {
536536
return response.blob();
537537
case 'json':
538538
return response.json();
539+
case undefined:
539540
case '':
540541
case 'text':
541542
return response.text();
@@ -544,6 +545,9 @@ WireClient._fetchRequest = function (method, url, options) {
544545
}
545546
}).then(function (processedBody) {
546547
syntheticXhr.response = processedBody;
548+
if (!options.responseType || options.responseType === 'text') {
549+
syntheticXhr.responseText = processedBody;
550+
}
547551
return syntheticXhr;
548552
});
549553

0 commit comments

Comments
 (0)