mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2024-11-21 09:36:35 +00:00
fix: Error Handle
This commit is contained in:
parent
5065a052fb
commit
d79b98bd55
@ -37,17 +37,17 @@ abstract class BaseAction<PayloadType, ReturnDataType> {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public async handle(payload: PayloadType): Promise<OB11Return<ReturnDataType | null>> {
|
public async handle(payload: PayloadType, echo: any = null): Promise<OB11Return<ReturnDataType | null>> {
|
||||||
const result = await this.check(payload);
|
const result = await this.check(payload);
|
||||||
if (!result.valid) {
|
if (!result.valid) {
|
||||||
return OB11Response.error(result.message, 400);
|
return OB11Response.error(result.message, 400, echo);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const resData = await this._handle(payload);
|
const resData = await this._handle(payload);
|
||||||
return OB11Response.ok(resData);
|
return OB11Response.ok(resData, echo);
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
this.core.context.logger.logError('发生错误', e);
|
this.core.context.logger.logError('发生错误', e);
|
||||||
return OB11Response.error(e?.toString() || e?.stack?.toString() || '未知错误,可能操作超时', 200);
|
return OB11Response.error(e?.toString() || e?.stack?.toString() || '未知错误,可能操作超时', 200, echo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -135,7 +135,7 @@ export class OB11ActiveWebSocketAdapter implements IOB11NetworkAdapter {
|
|||||||
try {
|
try {
|
||||||
receiveData = JSON.parse(message.toString());
|
receiveData = JSON.parse(message.toString());
|
||||||
echo = receiveData.echo;
|
echo = receiveData.echo;
|
||||||
this.logger.logDebug('[OneBot] [WebSocket Client] 收到正向Websocket消息', receiveData);
|
//this.logger.logDebug('[OneBot] [WebSocket Client] 收到正向Websocket消息', receiveData);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.checkStateAndReply<any>(OB11Response.error('json解析失败,请检查数据格式', 1400, echo));
|
this.checkStateAndReply<any>(OB11Response.error('json解析失败,请检查数据格式', 1400, echo));
|
||||||
return;
|
return;
|
||||||
@ -147,7 +147,7 @@ export class OB11ActiveWebSocketAdapter implements IOB11NetworkAdapter {
|
|||||||
this.checkStateAndReply<any>(OB11Response.error('不支持的api ' + receiveData.action, 1404, echo));
|
this.checkStateAndReply<any>(OB11Response.error('不支持的api ' + receiveData.action, 1404, echo));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const retdata = await action?.websocketHandle(receiveData.params, echo ?? '');
|
const retdata = await action.websocketHandle(receiveData.params, echo ?? '');
|
||||||
const packet = Object.assign({}, retdata);
|
const packet = Object.assign({}, retdata);
|
||||||
this.checkStateAndReply<any>(packet);
|
this.checkStateAndReply<any>(packet);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user