This commit is contained in:
Benjamin Toby
2025-02-19 20:01:50 +01:00
parent c08db13f3d
commit e9bb9fb07f
113 changed files with 253 additions and 63 deletions
+4 -2
View File
@@ -83,8 +83,10 @@ export default async function post({
try {
JSON.parse(reqPayloadString);
} catch (error) {
console.log(error);
console.log(reqPayloadString);
global.ERROR_CALLBACK?.(
`Error Parsing HTTP response for post action`,
error as Error
);
return {
success: false,
+1
View File
@@ -87,6 +87,7 @@ export default async function uploadImage({
return httpResponse as Return;
} catch (error: any) {
console.log("Error in uploading file: ", error.message);
global.ERROR_CALLBACK?.(`Error Uploading File`, error as Error);
return {
success: false,
+1
View File
@@ -91,6 +91,7 @@ export default async function uploadImage({
return httpResponse as FunctionReturn;
} catch (error: any) {
console.log("Error in uploading image: ", error.message);
global.ERROR_CALLBACK?.(`Error Uploading Image`, error as Error);
return {
success: false,
@@ -80,6 +80,8 @@ export default function getToken({
*/
return { key, csrf };
} catch (error) {
global.ERROR_CALLBACK?.(`Error Getting Token`, error as Error);
/**
* Return User Object
*
+6 -1
View File
@@ -229,7 +229,12 @@ export default async function loginUser({
try {
if (token && encryptedPayload)
httpResponse["token"] = encryptedPayload;
} catch (error) {}
} catch (error) {
global.ERROR_CALLBACK?.(
`Login User HTTP Response Error`,
error as Error
);
}
const cookieNames = getAuthCookieNames({
database,
@@ -117,6 +117,8 @@ export default function logoutUser({
};
} catch (error: any) {
console.log("Logout Error:", error.message);
global.ERROR_CALLBACK?.(`Logout User Error`, error as Error);
return {
success: false,
msg: "Logout Failed",
@@ -183,7 +183,10 @@ export default async function githubAuth({
try {
resolve(JSON.parse(str));
} catch (error) {
console.log(error);
global.ERROR_CALLBACK?.(
`Github Auth Error`,
error as Error
);
resolve({
success: false,
@@ -199,6 +199,8 @@ export default function userAuth({
payload: userObject,
};
} catch (error: any) {
global.ERROR_CALLBACK?.(`User Auth Error`, error as Error);
/**
* Return User Object
*
@@ -44,6 +44,10 @@ export default async function validateTempEmailCode({
return null;
} catch (error: any) {
global.ERROR_CALLBACK?.(
`Validate Temp Email Code Error`,
error as Error
);
console.log("validateTempEmailCode error:", error.message);
return null;
}
@@ -66,6 +66,7 @@ export default function validateToken({
*/
return userObject;
} catch (error) {
global.ERROR_CALLBACK?.(`Validate Token Error`, error as Error);
/**
* Return User Object
*
@@ -101,6 +101,8 @@ export default async function apiGet<
message: error.message,
});
global.ERROR_CALLBACK?.(`API Get Error`, error as Error);
if (debug && global.DSQL_USE_LOCAL) {
console.log("apiGet:error", error.message);
}
@@ -94,6 +94,8 @@ export default async function apiPost({
message: error.message,
});
global.ERROR_CALLBACK?.(`API Post Error`, error as Error);
return {
success: false,
payload: results,
@@ -139,6 +139,8 @@ export default async function googleLogin({
message: error.message,
});
global.ERROR_CALLBACK?.(`Google Login Error`, error as Error);
loginFailureReason = error;
isUserValid = false;
@@ -271,6 +271,8 @@ export default async function handleSocialDb({
error.message
);
global.ERROR_CALLBACK?.(`Handle Social DB Error`, error as Error);
return {
success: false,
payload: null,
@@ -132,6 +132,11 @@ export default async function addAdminUserOnLogin({
);
}
} catch (error: any) {
global.ERROR_CALLBACK?.(
`Add Admin User On Login Error`,
error as Error
);
serverError({
component: "addAdminUserOnLogin",
message: error.message,
@@ -22,6 +22,10 @@ export const initAuthFiles = () => {
return true;
} catch (error: any) {
console.log(`Error initializing Auth Files: ${error.message}`);
global.ERROR_CALLBACK?.(
`Error Initializing Auth Files`,
error as Error
);
return false;
}
};
@@ -170,6 +170,7 @@ export default async function addDbEntry({
}
} catch (error: any) {
console.log("DSQL: Error in parsing data keys =>", error.message);
global.ERROR_CALLBACK?.(`Error parsing Data Keys`, error as Error);
continue;
}
}
@@ -54,6 +54,7 @@ export default async function deleteDbEntry({
*/
return deletedEntry;
} catch (error) {
global.ERROR_CALLBACK?.(`Error Deleting Entry`, error as Error);
return null;
}
}
@@ -49,6 +49,8 @@ export default async function dbHandler(...args: any[]) {
results = null;
global.ERROR_CALLBACK?.(`DB Handler Error`, error as Error);
serverError({
component: "dbHandler",
message: error.message,
@@ -41,6 +41,8 @@ export default async function fullAccessDbHandler({
} catch (error: any) {
////////////////////////////////////////
global.ERROR_CALLBACK?.(`Full Access DB Handler Error`, error as Error);
serverError({
component: "fullAccessDbHandler",
message: error.message,
@@ -26,6 +26,11 @@ export default function grabUserSchemaData({
message: error.message,
});
global.ERROR_CALLBACK?.(
`Error Grabbing User Schema Data`,
error as Error
);
return null;
}
}
@@ -33,6 +33,8 @@ export default function setUserSchemaData({
message: error.message,
});
global.ERROR_CALLBACK?.(`Error Setting User Schema`, error as Error);
return false;
}
}
@@ -65,7 +65,10 @@ export default async function updateUsersTableSchema({
return `Done!`;
} catch (error: any) {
console.log(`addUsersTableToDb.ts ERROR: ${error.message}`);
global.ERROR_CALLBACK?.(
`Error Updating User Table Schema`,
error as Error
);
serverError({
component: "addUsersTableToDb",
@@ -55,6 +55,9 @@ export default async function varDatabaseDbHandler({
database,
error
);
global.ERROR_CALLBACK?.(`VarDb Handler Error`, error as Error);
serverError({
component: "varDatabaseDbHandler/lines-52-53",
message: error.message,
@@ -34,6 +34,8 @@ export default async function varReadOnlyDatabaseDbHandler({
noMail: true,
});
global.ERROR_CALLBACK?.(`VarReadOnlyDB Handler Error`, error as Error);
return error.message;
} finally {
DB_CONN?.end();
+1
View File
@@ -52,6 +52,7 @@ export default function decrypt({
return decrypted;
} catch (error: any) {
console.log("Error in decrypting =>", error.message);
global.ERROR_CALLBACK?.(`Error Decrypting data`, error as Error);
return encryptedString;
}
}
+1
View File
@@ -53,6 +53,7 @@ export default function encrypt({
return encrypted;
} catch (error: any) {
console.log("Error in encrypting =>", error.message);
global.ERROR_CALLBACK?.(`Error Encrypting Data`, error as Error);
return data;
}
}
+1
View File
@@ -23,6 +23,7 @@ import grabDSQLConnection from "../utils/grab-dsql-connection";
console.log("Connection Query Success =>", result);
} catch (error: any) {
console.log("Connection query ERROR =>", error.message);
global.ERROR_CALLBACK?.(`Error Checking DB`, error as Error);
} finally {
CONNECTION?.end();
process.exit();
@@ -67,6 +67,10 @@ export default async function checkDbRecordCreateDbSchema({
return recordedDbEntry;
} catch (error) {
global.ERROR_CALLBACK?.(
`Error Checking DB Record on Creating Schema`,
error as Error
);
return undefined;
}
}
@@ -110,6 +110,10 @@ export default async function checkTableRecordCreateDbSchema({
return recordedTableEntry;
} catch (error) {
global.ERROR_CALLBACK?.(
`Error Checking Table Record on Creating Schema`,
error as Error
);
return undefined;
}
}
@@ -42,6 +42,11 @@ export default async function handleIndexescreateDbFromSchema({
if (!existingKeyInDb[0])
throw new Error("This Index Does not Exist");
} catch (error) {
global.ERROR_CALLBACK?.(
`Error Handling Indexes on Creating Schema`,
error as Error
);
/**
* @description Create new index if determined that it
* doesn't exist in MYSQL db
@@ -250,7 +250,10 @@ export default async function refreshUsersAndGrants({
}
}
} catch (error: any) {
console.log(`Error in adding SQL user =>`, error.message);
global.ERROR_CALLBACK?.(
`Error Refreshing MariaDB Users and Grants`,
error as Error
);
}
}
}
@@ -59,9 +59,9 @@ async function resetSQLCredentialsPasswords() {
);
}
} catch (error: any) {
console.log(
`Error Updating User ${user.id} Password =>`,
error.message
global.ERROR_CALLBACK?.(
`Error Resetting MariaDB User Password`,
error as Error
);
}
}
@@ -168,7 +168,7 @@ async function createUser() {
return true;
} catch (error: any) {
console.log(`Error in creating user => ${error.message}`);
global.ERROR_CALLBACK?.(`Error Creating User`, error as Error);
return false;
}
}
@@ -56,7 +56,7 @@ async function createUser() {
return true;
} catch (error: any) {
console.log(`Error in creating user => ${error.message}`);
global.ERROR_CALLBACK?.(`Error Updating User`, error as Error);
return false;
}
}
@@ -66,6 +66,10 @@ async function resetSQLCredentials() {
`User ${user.id}: ${user.first_name} ${user.last_name} SQL credentials successfully added.`
);
} catch (error: any) {
global.ERROR_CALLBACK?.(
`Error Resetting SQL credentials`,
error as Error
);
console.log(`Error in adding SQL user =>`, error.message);
}
}
@@ -47,9 +47,9 @@ async function resetSQLCredentialsPasswords() {
`User ${user.id}: ${user.first_name} ${user.last_name} Password Updated successfully added.`
);
} catch (error: any) {
console.log(
`Error Updating User ${user.id} Password =>`,
error.message
global.ERROR_CALLBACK?.(
`Error Updating MariaDB User`,
error as Error
);
}
}
+4 -1
View File
@@ -60,7 +60,10 @@ async function setSQLCredentials() {
`User ${user.id}: ${user.first_name} ${user.last_name} SQL credentials successfully added.`
);
} catch (error: any) {
console.log(`Error in adding SQL user =>`, error.message);
global.ERROR_CALLBACK?.(
`Error Setting SQL credentials`,
error as Error
);
}
}
}
+4 -1
View File
@@ -27,7 +27,10 @@ import grabDSQLConnection from "../utils/grab-dsql-connection";
console.log("parsedResults =>", parsedResults);
} catch (error: any) {
console.log("Connection query ERROR =>", error.message);
global.ERROR_CALLBACK?.(
`Error Testing External Server`,
error as Error
);
} finally {
CONNECTION?.end();
process.exit();
+1 -1
View File
@@ -75,7 +75,7 @@ export default async function testSQLEscape() {
`User ${user.id}: ${user.first_name} ${user.last_name} SQL credentials successfully added.`
);
} catch (error: any) {
console.log(`Error in adding SQL user =>`, error.message);
global.ERROR_CALLBACK?.(`Error Testing SQL Escape`, error as Error);
}
}
@@ -45,7 +45,10 @@ async function updateChildrenTablesOnDb() {
}
}
} catch (error) {
console.log(error);
global.ERROR_CALLBACK?.(
`Error Updating Children Tables on DB`,
error as Error
);
}
process.exit();
@@ -42,6 +42,11 @@ varDatabaseDbHandler({
message: error.message,
user: {},
});
global.ERROR_CALLBACK?.(
`Error Updating DB Slugs For Table Records`,
error as Error
);
}
}
+1 -1
View File
@@ -46,7 +46,7 @@ import grabDSQLConnection from "../utils/grab-dsql-connection";
console.log(`addUserSSL => ${User}@${Host}`, addUserSSL);
}
} catch (error: any) {
console.log("Connection query ERROR =>", error.message);
global.ERROR_CALLBACK?.(`Error Updating SSL Users`, error as Error);
} finally {
CONNECTION.end();
process.exit();
+2
View File
@@ -26,6 +26,8 @@ export default async function dbHandler({
results = await CONNECTION.query(query);
}
} catch (error: any) {
global.ERROR_CALLBACK?.(`DB Handler Error...`, error as Error);
if (process.env.FIRST_RUN) {
return null;
}
@@ -8,7 +8,7 @@ export default async function noDatabaseDbHandler(
try {
results = await dbHandler({ query: queryString });
} catch (error: any) {
console.log("ERROR in noDatabaseDbHandler =>", error.message);
global.ERROR_CALLBACK?.(`No DB Handler Error`, error as Error);
}
if (results) {
+2
View File
@@ -1523,3 +1523,5 @@ export type DsqlCrudParam<
sanitize?: (data?: T) => T;
debug?: boolean;
};
export type ErrorCallback = (title: string, error: Error) => void;
@@ -15,7 +15,7 @@ export default async function DB_HANDLER(...args: any[]) {
return JSON.parse(JSON.stringify(results));
} catch (error: any) {
console.log("DB Error =>", error);
global.ERROR_CALLBACK?.(`DB_HANDLER Error`, error as Error);
return {
success: false,
error: error.message,
@@ -23,7 +23,7 @@ export default async function DSQL_USER_DB_HANDLER({
try {
return await connDbHandler(CONNECTION, queryString, queryValues);
} catch (error: any) {
console.log(`DSQL_USER_DB_HANDLER Error: ${error.message}`);
global.ERROR_CALLBACK?.(`DSQL_USER_DB_HANDLER Error`, error as Error);
return null;
} finally {
CONNECTION?.end();
@@ -11,7 +11,7 @@ export default async function LOCAL_DB_HANDLER(...args: any[]) {
return JSON.parse(JSON.stringify(results));
} catch (error: any) {
console.log("DB Error =>", error.message);
global.ERROR_CALLBACK?.(`LOCAL_DB_HANDLER Error`, error as Error);
return {
success: false,
error: error.message,
@@ -24,6 +24,7 @@ export default function NO_DB_HANDLER(...args: any[]) {
});
});
} catch (error: any) {
global.ERROR_CALLBACK?.(`NO_DB_HANDLER Error`, error as Error);
return {
success: false,
error: error.message,
@@ -22,6 +22,7 @@ export default function ROOT_DB_HANDLER(...args: any[]) {
});
});
} catch (error: any) {
global.ERROR_CALLBACK?.(`ROOT_DB_HANDLER Error`, error as Error);
return {
success: false,
error: error.message,
+1 -2
View File
@@ -45,8 +45,7 @@ export default function parseCookies({
return cookieObject;
} catch (error: any) {
console.log(`ERROR parsing cookies: ${error.message}`);
global.ERROR_CALLBACK?.(`Parse Cookies Error`, error as Error);
return {};
}
}
@@ -210,6 +210,7 @@ export default async function dsqlMethodCrud<
}
return result;
} catch (error) {
global.ERROR_CALLBACK?.(`Method Crud Error`, error as Error);
return result;
}
}
+5 -3
View File
@@ -45,7 +45,10 @@ export default async function connDbHandler<ReturnType = any>(
);
resArray.push(JSON.parse(JSON.stringify(queryObjRes)));
} catch (error: any) {
console.log(`connDbHandler Query Error: ${error.message}`);
global.ERROR_CALLBACK?.(
`Connection DB Handler Query Error`,
error as Error
);
resArray.push(null);
}
}
@@ -55,8 +58,7 @@ export default async function connDbHandler<ReturnType = any>(
return null;
}
} catch (error: any) {
console.log(`connDbHandler Error: ${error.message}`);
console.log(conn?.config());
global.ERROR_CALLBACK?.(`Connection DB Handler Error`, error as Error);
return null;
} finally {
conn?.end();