refactor(sql): improved the return function to show data [] when not connected, prevents crashes

This commit is contained in:
2025-04-24 21:24:39 -05:00
parent 3573fd1a5b
commit ead63d4b41
36 changed files with 323 additions and 141 deletions

View File

@@ -164,6 +164,7 @@ export async function query(queryToRun: string, name: string) {
return {
success: false,
message: `The sql ${dbServer[0].value} is not not connected`,
data: [],
};
}
/**
@@ -178,7 +179,11 @@ export async function query(queryToRun: string, name: string) {
try {
const result = await pool.request().query(query);
return result.recordset;
return {
success: true,
message: `Query results for: ${name}`,
data: result.recordset,
};
} catch (error: any) {
if (error.code === "ETIMEOUT") {
createLog(
@@ -189,13 +194,23 @@ export async function query(queryToRun: string, name: string) {
error
)}, ${name} did not run due to a timeout.`
);
throw new Error(`${name} query did not run due to a timeout.`);
//throw new Error(`${name} query did not run due to a timeout.`);
return {
success: false,
message: `${name} query did not run due to a timeout.`,
data: [],
};
}
if (error.code === "EREQUEST") {
throw new Error(
`${name} encoutnered an error ${error.originalError.info.message}`
);
// throw new Error(
// `${name} encoutnered an error ${error.originalError.info.message}`
// );
return {
success: false,
message: `${name} encoutnered an error ${error.originalError.info.message}`,
data: [],
};
}
//console.log(error.originalError.info.message);