feat: enhance QueryPlugin run method with error handling and update logging in Vm class
This commit is contained in:
@ -15,8 +15,30 @@ export class QueryPlugin extends Plugin {
|
|||||||
return new QueryPlugin("query", query, queryExecuterService);
|
return new QueryPlugin("query", query, queryExecuterService);
|
||||||
}
|
}
|
||||||
|
|
||||||
async run(data): Promise<any> {
|
async run(data: {
|
||||||
return await this.QueryExecuterService.runQuery(this.query.id, data);
|
token: string;
|
||||||
|
queryData: any;
|
||||||
|
headers?: Record<string, any>;
|
||||||
|
}): Promise<any> {
|
||||||
|
const query = await this.QueryExecuterService.queryRepository.findOne({
|
||||||
|
where: { id: this.query.id },
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!query) {
|
||||||
|
throw new Error(`Query with id ${this.query.id} not found`);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (query.isCommand && !this.query.isCommand) {
|
||||||
|
throw new Error(
|
||||||
|
`Query with id ${this.query.id} is a command and cannot be called from query`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return await this.QueryExecuterService.runQuery(
|
||||||
|
query.id,
|
||||||
|
data.queryData,
|
||||||
|
data.headers
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
onFinish() {
|
onFinish() {
|
||||||
|
|||||||
@ -85,7 +85,7 @@ export class Vm {
|
|||||||
});
|
});
|
||||||
|
|
||||||
this.setFunction("returnResult", (res) => {
|
this.setFunction("returnResult", (res) => {
|
||||||
console.log("Returning result from VM:", res);
|
// console.log("Returning result from VM:", res);
|
||||||
|
|
||||||
resolvePromise(res);
|
resolvePromise(res);
|
||||||
});
|
});
|
||||||
|
|||||||
@ -17,7 +17,7 @@ async function main(input, headers) {
|
|||||||
|
|
||||||
const res = await db.execute(sql);
|
const res = await db.execute(sql);
|
||||||
|
|
||||||
log(res);
|
// log(res);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
response: {
|
response: {
|
||||||
|
|||||||
Reference in New Issue
Block a user