Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

Commit e6115de

Browse files
committed
request-fetch-adapter
1 parent ebd93b5 commit e6115de

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

request-fetch-adapter.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
1-
module.exports.request = function request(verb, url, body, callback) {
1+
let request = async (verb, url, body, callback) => {
22
if (typeof body === "function") {
33
callback = body;
44
body = null;
55
}
66

77
var headers = {
8-
'Accept': 'application/json',
9-
'Content-Type': 'application/json'
8+
"Accept": "application/json",
9+
"Content-Type": "application/json"
1010
};
1111

1212
if (body && typeof body === "object") {
1313
body = JSON.stringify(body);
1414
}
1515

16-
var statusCode;
17-
18-
fetch(url, {
19-
method: verb,
20-
headers: headers,
21-
body: body
22-
}).then(function(response) {
23-
statusCode = response.status;
24-
return response.text();
25-
}).then(function(body) {
16+
try {
17+
var statusCode;
18+
let response = await fetch(url, {
19+
method: verb,
20+
headers: headers,
21+
body: body
22+
});
23+
24+
let statusCode = response.status;
25+
let body = await response.text();
2626
callback(null, {statusCode: statusCode, body: body});
27-
}).catch(function(err) {
27+
} catch (err) {
2828
callback(err);
29-
});
29+
}
3030
}

0 commit comments

Comments
 (0)