diff --git a/apps/web/graphql/users/logic.ts b/apps/web/graphql/users/logic.ts index 09b62f6c3..f2913bc26 100644 --- a/apps/web/graphql/users/logic.ts +++ b/apps/web/graphql/users/logic.ts @@ -261,7 +261,9 @@ export async function createUser({ newUser.lead = lead; const user = await UserModel.create(newUser); - await initMandatoryPages(domain, user); + if (!notTheFirstUserOfDomain) { + await initMandatoryPages(domain, user); + } return user; } diff --git a/apps/web/pages/api/auth/login.ts b/apps/web/pages/api/auth/login.ts index d1c1257d5..ed98b9715 100644 --- a/apps/web/pages/api/auth/login.ts +++ b/apps/web/pages/api/auth/login.ts @@ -10,11 +10,16 @@ import { setLoginSession } from "../../../lib/auth"; import { responses } from "../../../config/strings"; import connectDb from "../../../middlewares/connect-db"; import User from "../../../models/User"; +import { error } from "../../../services/logger"; passport.use(magicLinkStrategy); export default nc({ onError: (err, req, res, next) => { + error(err.message, { + fileName: `/api/auth/login.ts`, + stack: err.stack, + }); res.status(500).json({ error: err.message }); }, onNoMatch: (req, res) => { diff --git a/apps/web/pages/api/graph.ts b/apps/web/pages/api/graph.ts index 41a405454..323d25bbd 100644 --- a/apps/web/pages/api/graph.ts +++ b/apps/web/pages/api/graph.ts @@ -8,11 +8,19 @@ import jwtStrategy from "../../lib/jwt"; import ApiRequest from "../../models/ApiRequest"; import connectDb from "../../middlewares/connect-db"; import constants from "../../config/constants"; +import { error } from "../../services/logger"; +import { responses } from "../../config/strings"; passport.use(jwtStrategy); export default nc({ onError: (err, req, res, next) => { + if (err.message.indexOf(responses.domain_doesnt_exist) === -1) { + error(err.message, { + fileName: `/api/graph.ts`, + stack: err.stack, + }); + } res.status(500).json({ error: err.message }); }, onNoMatch: (req, res) => { diff --git a/apps/web/pages/api/media/[mediaId].ts b/apps/web/pages/api/media/[mediaId].ts index 99955f131..7d5b6b35e 100644 --- a/apps/web/pages/api/media/[mediaId].ts +++ b/apps/web/pages/api/media/[mediaId].ts @@ -9,12 +9,17 @@ import connectDb from "../../../middlewares/connect-db"; import verifyDomain from "../../../middlewares/verify-domain"; import verifyJwt from "../../../middlewares/verify-jwt"; import ApiRequest from "../../../models/ApiRequest"; +import { error } from "../../../services/logger"; import * as medialitService from "../../../services/medialit"; passport.use(jwtStrategy); export default nc({ onError: (err, req, res, next) => { + error(err.message, { + fileName: `/api/media/[mediaId].ts`, + stack: err.stack, + }); res.status(500).json({ error: err.message }); }, onNoMatch: (req, res) => { diff --git a/apps/web/pages/api/media/index.ts b/apps/web/pages/api/media/index.ts index 7f3745ecc..bc1b703a8 100644 --- a/apps/web/pages/api/media/index.ts +++ b/apps/web/pages/api/media/index.ts @@ -9,12 +9,17 @@ import connectDb from "../../../middlewares/connect-db"; import verifyDomain from "../../../middlewares/verify-domain"; import verifyJwt from "../../../middlewares/verify-jwt"; import ApiRequest from "../../../models/ApiRequest"; +import { error } from "../../../services/logger"; import * as medialitService from "../../../services/medialit"; passport.use(jwtStrategy); export default nc({ onError: (err, req, res, next) => { + error(err.message, { + fileName: `/api/media/index.ts`, + stack: err.stack, + }); res.status(500).json({ error: err.message }); }, onNoMatch: (req, res) => { diff --git a/apps/web/pages/api/media/presigned.ts b/apps/web/pages/api/media/presigned.ts index 1107ef888..0a690409b 100644 --- a/apps/web/pages/api/media/presigned.ts +++ b/apps/web/pages/api/media/presigned.ts @@ -9,12 +9,17 @@ import connectDb from "../../../middlewares/connect-db"; import verifyDomain from "../../../middlewares/verify-domain"; import verifyJwt from "../../../middlewares/verify-jwt"; import ApiRequest from "../../../models/ApiRequest"; +import { error } from "../../../services/logger"; import * as medialitService from "../../../services/medialit"; passport.use(jwtStrategy); export default nc({ onError: (err, req, res, next) => { + error(err.message, { + fileName: `/api/media/presigned.ts`, + stack: err.stack, + }); res.status(500).json({ error: err.message }); }, onNoMatch: (req, res) => { diff --git a/apps/web/pages/api/payment/initiate.ts b/apps/web/pages/api/payment/initiate.ts index 0ec0c270e..4512e7c04 100644 --- a/apps/web/pages/api/payment/initiate.ts +++ b/apps/web/pages/api/payment/initiate.ts @@ -12,6 +12,7 @@ import CourseModel, { Course } from "../../../models/Course"; import { getPaymentMethod } from "../../../payments"; import PurchaseModel from "../../../models/Purchase"; import finalizePurchase from "../../../lib/finalize-purchase"; +import { error } from "../../../services/logger"; const { transactionSuccess, transactionFailed, transactionInitiated } = constants; @@ -20,6 +21,10 @@ passport.use(jwtStrategy); export default nc({ onError: (err, req, res, next) => { + error(err.message, { + fileName: `/api/payment/initiate.ts`, + stack: err.stack, + }); res.status(500).json({ error: err.message }); }, onNoMatch: (req, res) => { diff --git a/apps/web/pages/api/payment/verify.ts b/apps/web/pages/api/payment/verify.ts index 9fb583b2c..2acffd54e 100644 --- a/apps/web/pages/api/payment/verify.ts +++ b/apps/web/pages/api/payment/verify.ts @@ -8,11 +8,16 @@ import verifyDomain from "../../../middlewares/verify-domain"; import verifyJwt from "../../../middlewares/verify-jwt"; import ApiRequest from "../../../models/ApiRequest"; import PurchaseModel, { Purchase } from "../../../models/Purchase"; +import { error } from "../../../services/logger"; passport.use(jwtStrategy); export default nc({ onError: (err, req, res, next) => { + error(err.message, { + fileName: `/api/payment/verify.ts`, + stack: err.stack, + }); res.status(500).json({ error: err.message }); }, onNoMatch: (req, res) => { diff --git a/apps/web/pages/api/payment/webhook.ts b/apps/web/pages/api/payment/webhook.ts index 0998828cf..122382889 100644 --- a/apps/web/pages/api/payment/webhook.ts +++ b/apps/web/pages/api/payment/webhook.ts @@ -8,10 +8,15 @@ import verifyDomain from "../../../middlewares/verify-domain"; import ApiRequest from "../../../models/ApiRequest"; import PurchaseModel, { Purchase } from "../../../models/Purchase"; import { getPaymentMethod } from "../../../payments"; +import { error } from "../../../services/logger"; const { transactionSuccess } = constants; export default nc({ onError: (err, req, res, next) => { + error(err.message, { + fileName: `/api/payment/webhook.ts`, + stack: err.stack, + }); res.status(500).json({ error: err.message }); }, onNoMatch: (req, res) => { diff --git a/apps/web/services/logger.ts b/apps/web/services/logger.ts index a77697a2a..c50830d1a 100644 --- a/apps/web/services/logger.ts +++ b/apps/web/services/logger.ts @@ -27,7 +27,10 @@ export const warn = async ( export const error = async ( message: string, - metadata?: Record + metadata?: { + fileName?: string; + stack?: Record; + } ) => { await Log.create({ severity: severityError,