mirror of
https://github.com/TheRealOwenRees/echecsfrance.git
synced 2026-07-22 20:16:57 +00:00
logger added
This commit is contained in:
@@ -23,12 +23,11 @@ DESIGN CHANGES
|
|||||||
|
|
||||||
----------------------------------------------------------------
|
----------------------------------------------------------------
|
||||||
LOGIC
|
LOGIC
|
||||||
//TODO error handling
|
//TODO error handling - check everything, wrap in try/catch or use library to handle, log errors
|
||||||
//TODO consider offering GraphQL support
|
//TODO consider offering GraphQL support
|
||||||
|
|
||||||
MISC
|
MISC
|
||||||
----------------------------------------------------------------
|
----------------------------------------------------------------
|
||||||
//TODO write logger (fullstack open examples)
|
|
||||||
//TODO multi-language i18n support - https://nextjs.org/docs/app/building-your-application/routing/internationalization
|
//TODO multi-language i18n support - https://nextjs.org/docs/app/building-your-application/routing/internationalization
|
||||||
//TODO move smaller ui components into a new folder, and make them reusable - such as using generic prop names
|
//TODO move smaller ui components into a new folder, and make them reusable - such as using generic prop names
|
||||||
//TODO readme
|
//TODO readme
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import NodeMailer from "nodemailer";
|
import NodeMailer from "nodemailer";
|
||||||
import { NextResponse } from "next/server";
|
import { NextResponse } from "next/server";
|
||||||
|
import { infoLog, errorLog } from "@/utils/logger";
|
||||||
|
|
||||||
export async function POST(req: Request) {
|
export async function POST(req: Request) {
|
||||||
const { email, subject, message } = await req.json();
|
const { email, subject, message } = await req.json();
|
||||||
@@ -21,14 +22,15 @@ export async function POST(req: Request) {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const info = await transporter.sendMail(mailContent);
|
const mailInfo = await transporter.sendMail(mailContent);
|
||||||
console.log(info);
|
infoLog(mailInfo);
|
||||||
|
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
{ success: `Message delivered to ${info.accepted}` },
|
{ success: `Message delivered to ${mailInfo.accepted}` },
|
||||||
{ status: 250 }
|
{ status: 250 }
|
||||||
);
|
);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
errorLog(error);
|
||||||
return NextResponse.json({ error: `Connection refused` }, { status: 404 });
|
return NextResponse.json({ error: `Connection refused` }, { status: 404 });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import clientPromise from "@/lib/mongodb";
|
import clientPromise from "@/lib/mongodb";
|
||||||
import { dateOrderingFrance } from "@/utils/dbDateOrdering";
|
import { dateOrderingFrance } from "@/utils/dbDateOrdering";
|
||||||
|
import { errorLog } from "@/utils/logger";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tournament data API endpoint
|
* Tournament data API endpoint
|
||||||
@@ -22,6 +23,7 @@ export async function GET() {
|
|||||||
|
|
||||||
return new Response(JSON.stringify(data), { status: 200, headers });
|
return new Response(JSON.stringify(data), { status: 200, headers });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
errorLog(error);
|
||||||
return new Response(JSON.stringify(error), { status: 500, headers });
|
return new Response(JSON.stringify(error), { status: 500, headers });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import dynamic from "next/dynamic";
|
|||||||
import Layout from "@/components/Layout";
|
import Layout from "@/components/Layout";
|
||||||
import TournamentTable from "@/components/TournamentTable";
|
import TournamentTable from "@/components/TournamentTable";
|
||||||
import { dateOrderingFrance } from "@/utils/dbDateOrdering";
|
import { dateOrderingFrance } from "@/utils/dbDateOrdering";
|
||||||
|
import { errorLog } from "@/utils/logger";
|
||||||
|
|
||||||
export const revalidate = 3600; // revalidate cache every 6 hours
|
export const revalidate = 3600; // revalidate cache every 6 hours
|
||||||
|
|
||||||
@@ -26,6 +27,7 @@ const getTournaments = async () => {
|
|||||||
const data = await dateOrderingFrance(db);
|
const data = await dateOrderingFrance(db);
|
||||||
return JSON.stringify(data);
|
return JSON.stringify(data);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
errorLog(error);
|
||||||
throw new Error("Error fetching tournament data");
|
throw new Error("Error fetching tournament data");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { Dispatch, FormEvent, SetStateAction } from "react";
|
import { Dispatch, FormEvent, SetStateAction } from "react";
|
||||||
import sendMail from "@/lib/sendMail";
|
import sendMail from "@/lib/sendMail";
|
||||||
|
import { errorLog } from "@/utils/logger";
|
||||||
|
|
||||||
export const handleEmailSubmit = async (
|
export const handleEmailSubmit = async (
|
||||||
e: FormEvent<HTMLFormElement>,
|
e: FormEvent<HTMLFormElement>,
|
||||||
@@ -34,7 +35,7 @@ export const handleEmailSubmit = async (
|
|||||||
setIsSending(false);
|
setIsSending(false);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error); //TODO add to logger
|
errorLog(error);
|
||||||
setResponseMessage({
|
setResponseMessage({
|
||||||
isSuccessful: false,
|
isSuccessful: false,
|
||||||
message: "Oops something went wrong. Please try again.",
|
message: "Oops something went wrong. Please try again.",
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
export const infoLog = (...params: any[]) => {
|
||||||
|
console.log(...params);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const errorLog = (...params: any[]) => {
|
||||||
|
console.error(...params);
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user