我无法用这个脚本解决我未处理的承诺拒绝。承诺和异步功能对我来说都是新的。我应该处理拒绝,但不知道它是如何工作的。
有人能帮我吗?
const rawRequest = async (url, headers, data, timeout) => {
// Set custom User-Agent string
headers['User-Agent'] = 'Kraken Javascript API Client';
const options = { headers, timeout };
Object.assign(options, {
method : 'POST',
body : qs.stringify(data),
});
const { body } = await got(url, options);
reject('reject');
const response = JSON.parse(body);
if(response.error && response.error.length) {
const error = response.error
.filter((e) => e.startsWith('E'))
.map((e) => e.substr(1));
if(!error.length) {
throw new Error("Kraken API returned an unknown error");
}
throw new Error(error.join(', '));
}
return response;
};
//script
const response = rawRequest(url, headers, params, timeout);
console.log(response);