mirror of
https://github.com/zhigang1992/react-native-code-push.git
synced 2026-06-10 15:49:36 +08:00
request-fetch-adapter
This commit is contained in:
@@ -1,30 +1,30 @@
|
||||
module.exports.request = function request(verb, url, body, callback) {
|
||||
let request = async (verb, url, body, callback) => {
|
||||
if (typeof body === "function") {
|
||||
callback = body;
|
||||
body = null;
|
||||
}
|
||||
|
||||
var headers = {
|
||||
'Accept': 'application/json',
|
||||
'Content-Type': 'application/json'
|
||||
"Accept": "application/json",
|
||||
"Content-Type": "application/json"
|
||||
};
|
||||
|
||||
if (body && typeof body === "object") {
|
||||
body = JSON.stringify(body);
|
||||
}
|
||||
|
||||
var statusCode;
|
||||
|
||||
fetch(url, {
|
||||
method: verb,
|
||||
headers: headers,
|
||||
body: body
|
||||
}).then(function(response) {
|
||||
statusCode = response.status;
|
||||
return response.text();
|
||||
}).then(function(body) {
|
||||
try {
|
||||
var statusCode;
|
||||
let response = await fetch(url, {
|
||||
method: verb,
|
||||
headers: headers,
|
||||
body: body
|
||||
});
|
||||
|
||||
let statusCode = response.status;
|
||||
let body = await response.text();
|
||||
callback(null, {statusCode: statusCode, body: body});
|
||||
}).catch(function(err) {
|
||||
} catch (err) {
|
||||
callback(err);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user