2017-08-13 19 views
0

未処理の約束の拒否をこのスクリプトで解決することはできません。約束と非同期機能は私にとって初めてのものです。 拒否を処理する必要がありますが、その仕組みがわかりません。処理されていない約束の拒否

誰かが私を助けることができますか?

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); 
+0

コードに適切なインデントがあると、コードを読むことができます。 – jfriend00

答えて

0

非同期関数の結果は当時のものです。

//script 
rawRequest(url, headers, params, timeout).then(res => { 
//do something with your response 
console.log(res); 
}).catch(e => { 
//handle exception (rejection) 
console.log(e); 
}) 

このようにrawRequest関数を呼び出してください(これは役に立ちません)。

+0

はすばやく反応してくれてありがとうございました – Zorrotwee

関連する問題