Commit 3d4d1bb9 authored by antoor's avatar antoor

Fixed asynchronous callback error prompt

修正异步回调错误提示
parent e64f4507
...@@ -187,16 +187,16 @@ class Base { ...@@ -187,16 +187,16 @@ class Base {
*/ */
request(code, chunkCallBack) { request(code, chunkCallBack) {
const opt = this.complete(code); const opt = this.complete(code);
return new Promise((ret, rej) => { return new Promise((res, rej) => {
// 随机ID(用于监听数据来源) // 随机ID(用于监听数据来源)
const hash = (String(+new Date) + String(Math.random())).substr(10, 10).replace('.', '_'); const hash = (String(+new Date) + String(Math.random())).substr(10, 10).replace('.', '_');
// 监听数据返回 // 监听数据返回
antSword['ipcRenderer'] antSword['ipcRenderer']
// 请求完毕返回数据{text,buff} // 请求完毕返回数据{text,buff}
.once(`request-${hash}`, (event, arg) => { .once(`request-${hash}`, (event, ret) => {
return ret({ return res({
'text': arg['text'], 'text': ret['text'],
'buff': arg['buff'] 'buff': ret['buff']
}); });
}) })
// HTTP请求返回字节流 // HTTP请求返回字节流
...@@ -205,7 +205,7 @@ class Base { ...@@ -205,7 +205,7 @@ class Base {
}) })
// 数据请求错误 // 数据请求错误
.once(`request-error-${hash}`, (event, ret) => { .once(`request-error-${hash}`, (event, ret) => {
throw new Error(ret); return rej(ret);
}) })
// 发送请求数据 // 发送请求数据
.send('request', { .send('request', {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment