summaryrefslogtreecommitdiff
path: root/ext/bg/js/request.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2019-12-27 18:58:11 -0500
committertoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-01-16 22:39:26 -0500
commit7686e56c00c724ad6f9e133134787e2cd083b062 (patch)
treecc8b5568543f2c5206e69677b6cf3fac2d16a9e4 /ext/bg/js/request.js
parentd512c111f6a5918eb3dfca3c0e3d5d69e73fb8b7 (diff)
Move display templates into a single file
Diffstat (limited to 'ext/bg/js/request.js')
-rw-r--r--ext/bg/js/request.js21
1 files changed, 12 insertions, 9 deletions
diff --git a/ext/bg/js/request.js b/ext/bg/js/request.js
index b584c9a9..778f933b 100644
--- a/ext/bg/js/request.js
+++ b/ext/bg/js/request.js
@@ -17,10 +17,10 @@
*/
-function requestJson(url, action, params) {
+function requestText(url, action, params) {
return new Promise((resolve, reject) => {
const xhr = new XMLHttpRequest();
- xhr.overrideMimeType('application/json');
+ xhr.overrideMimeType('text/plain');
xhr.addEventListener('load', () => resolve(xhr.responseText));
xhr.addEventListener('error', () => reject(new Error('Failed to connect')));
xhr.open(action, url);
@@ -29,12 +29,15 @@ function requestJson(url, action, params) {
} else {
xhr.send();
}
- }).then((responseText) => {
- try {
- return JSON.parse(responseText);
- }
- catch (e) {
- return Promise.reject(new Error('Invalid response'));
- }
});
}
+
+async function requestJson(url, action, params) {
+ const responseText = await requestText(url, action, params);
+ try {
+ return JSON.parse(responseText);
+ }
+ catch (e) {
+ throw new Error('Invalid response');
+ }
+}