Skip to content

Commit

Permalink
add some more error logs
Browse files Browse the repository at this point in the history
  • Loading branch information
birdpump committed Aug 11, 2024
1 parent b5fe488 commit b8802b2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
16 changes: 9 additions & 7 deletions controllers/app/appData.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {verificationQueue} from "../../models/verificationQueue.js";
import {sendVerificationEmail} from "../../utils/app/email/sendEmail.js";
import {queryAreaRestriction} from "../admin/adminData.js";
import {throwApplicationError} from "../../middleware/errorHandler.js";
import {logger} from "../../utils/admin/logging/logger.js";

import {validateToken} from "../../utils/app/turnstyle/validateToken.js";

Expand Down Expand Up @@ -206,18 +207,18 @@ export async function sendVerification(studentID, email) {
}

//this controller gets called from the route, will call send virefy and verify token
export async function sendVerifyStudents(data, token){
export async function sendVerifyStudents(data, token) {


let response = await validateToken(token);
if (response.success){
if (response.success) {

if(data.length > 2) throwApplicationError('cannot verify more than two students');
if (data.length > 2) throwApplicationError('cannot verify more than two students');

for(const student of data){
for (const student of data) {
const user = await UserData.findByPk(student);
await sendVerification(student, user.email); // todo removed return case here, make sure that is not needed
}
}
} else {
throwApplicationError('Captcha status invalid');
}
Expand All @@ -226,11 +227,11 @@ export async function sendVerifyStudents(data, token){

export async function verifyStudent(token, id) {

if(await checkVerification(id)){
if (await checkVerification(id)) {
return;
}

if(token == null){
if (token == null) {
throwApplicationError('Link Incomplete');
}

Expand All @@ -247,6 +248,7 @@ export async function verifyStudent(token, id) {
}
});

logger.info(`Student ${student.studentId} successfully registered`);
} else {
throwApplicationError('Verification Link Expired');
}
Expand Down
3 changes: 2 additions & 1 deletion middleware/errorHandler.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {logger} from "../utils/admin/logging/logger.js";
// Middleware to get errors from any route and handle the response
export const errorHandler = (err, req, res, next) => {

Expand All @@ -8,7 +9,7 @@ export const errorHandler = (err, req, res, next) => {
} else {
// Log the system error for debugging purposes
console.error(err);

logger.error(err.stack);
// For other errors, send a generic error message
res.status(500).json({error: 'Internal server error'});
}
Expand Down
3 changes: 1 addition & 2 deletions utils/admin/logging/getLogs.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,5 @@ export async function getLogs() {
const limitedLogs = logEntries.slice(-maxLogs);

return limitedLogs
.map(log => pretty(log))
// .join('\n');
.map(log => pretty(log));
}

0 comments on commit b8802b2

Please sign in to comment.