feat: added error debug message in root layout
Signed-off-by: Varun Raj <varun@skcript.com>
This commit is contained in:
1 parent
0597f34662
commit
ac0db7a741
9 files changed
+36
-24
No files matched your search
@@ -34,7 +34,6 @@ export default function AssetOffsetDialog({ assets: _assets, open, toggleOpen }:
|
|||||||
|
|
||||||
const handleSubmit = async (e: React.FormEvent<HTMLFormElement>) => {
|
const handleSubmit = async (e: React.FormEvent<HTMLFormElement>) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
console.log(offsetData);
|
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
const promises = assets.map(async (asset) => {
|
const promises = assets.map(async (asset) => {
|
||||||
setAssetStatus({ [asset.id]: 'pending' });
|
setAssetStatus({ [asset.id]: 'pending' });
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ export default function PeopleList() {
|
|||||||
setFilters((prev) => ({ ...prev, ...newConfig })),
|
setFilters((prev) => ({ ...prev, ...newConfig })),
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<PageLayout>
|
<PageLayout className="!p-0 !mb-0">
|
||||||
<Header
|
<Header
|
||||||
leftComponent="Manage People"
|
leftComponent="Manage People"
|
||||||
rightComponent={<PeopleFilters />}
|
rightComponent={<PeopleFilters />}
|
||||||
|
|||||||
+22
-5
@@ -1,14 +1,31 @@
|
|||||||
import { drizzle } from 'drizzle-orm/node-postgres';
|
import { drizzle, NodePgDatabase } from 'drizzle-orm/node-postgres';
|
||||||
|
|
||||||
import { Client } from "pg";
|
import { Client, Pool } from "pg";
|
||||||
import { ENV } from "./environment";
|
import { ENV } from "./environment";
|
||||||
import * as schema from "@/schema";
|
import * as schema from "@/schema";
|
||||||
|
import { sql } from 'drizzle-orm';
|
||||||
|
|
||||||
const client = new Client({
|
const pool = new Pool({
|
||||||
connectionString: ENV.DATABASE_URL,
|
connectionString: ENV.DATABASE_URL,
|
||||||
|
keepAlive: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
await client.connect();
|
class DatabaseConnectionError extends Error {
|
||||||
export const db = drizzle(client, {
|
error: string;
|
||||||
|
constructor(message: string, error: string) {
|
||||||
|
super(message);
|
||||||
|
this.name = "DatabaseConnectionError";
|
||||||
|
this.error = error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
export const connectDB = async (db: NodePgDatabase<typeof schema>) => {
|
||||||
|
try {
|
||||||
|
await db.execute(sql`SELECT 1`); // Execute a simple query
|
||||||
|
} catch (error: any) {
|
||||||
|
throw new DatabaseConnectionError(error.message, "Database connection failed");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const db = drizzle(pool, {
|
||||||
schema
|
schema
|
||||||
});
|
});
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
import { appConfig } from "@/config/app.config"
|
import { appConfig } from "@/config/app.config"
|
||||||
|
import { connectDB, db } from "@/config/db"
|
||||||
import { ENV } from "@/config/environment"
|
import { ENV } from "@/config/environment"
|
||||||
import { getCookie } from "@/lib/cookie"
|
import { getCookie } from "@/lib/cookie"
|
||||||
import { NextApiRequest } from "next"
|
import { NextApiRequest } from "next"
|
||||||
@@ -40,6 +41,7 @@ export const getCurrentUserFromAccessToken = (token: string) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const getCurrentUser = async (req: NextApiRequest) => {
|
export const getCurrentUser = async (req: NextApiRequest) => {
|
||||||
|
await connectDB(db);
|
||||||
const session = getCookie(req, appConfig.sessionCookieName)
|
const session = getCookie(req, appConfig.sessionCookieName)
|
||||||
|
|
||||||
if (session) {
|
if (session) {
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ export const offsetDate = (date: string, offset: {
|
|||||||
minutes: number,
|
minutes: number,
|
||||||
seconds: number
|
seconds: number
|
||||||
}): string => {
|
}): string => {
|
||||||
console.log(offset)
|
|
||||||
const parsedDate = new Date(date);
|
const parsedDate = new Date(date);
|
||||||
const result = addYears(parsedDate, offset.years || 0)
|
const result = addYears(parsedDate, offset.years || 0)
|
||||||
const result2 = addDays(result, offset.days || 0)
|
const result2 = addDays(result, offset.days || 0)
|
||||||
|
|||||||
+10
-8
@@ -4,19 +4,21 @@ import qs from 'qs'
|
|||||||
|
|
||||||
|
|
||||||
const handleErrors = (error: AxiosError | any) => {
|
const handleErrors = (error: AxiosError | any) => {
|
||||||
if (error.code === "ERR_BAD_RESPONSE") {
|
|
||||||
|
let errorObject = {}
|
||||||
|
if (error.response && error.response.data) {
|
||||||
|
return Promise.reject({
|
||||||
|
error: error.response.data.error,
|
||||||
|
message: error.response.data.message,
|
||||||
|
status: error.response.status,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
else if (error.code === "ERR_BAD_RESPONSE") {
|
||||||
return Promise.reject({
|
return Promise.reject({
|
||||||
error: "Unable to process this request, please try again later",
|
error: "Unable to process this request, please try again later",
|
||||||
message: error.code,
|
message: error.code,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
let errorObject = {}
|
|
||||||
if (error.response) {
|
|
||||||
return Promise.reject({
|
|
||||||
...error.response.data,
|
|
||||||
status: error.response.status,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
errorObject = {
|
errorObject = {
|
||||||
message: 'Network Error. Please check your connection and try again!',
|
message: 'Network Error. Please check your connection and try again!',
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,9 +21,6 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
|||||||
body: req.method !== 'GET' && req.method !== 'HEAD' ? JSON.stringify(req.body) : null,
|
body: req.method !== 'GET' && req.method !== 'HEAD' ? JSON.stringify(req.body) : null,
|
||||||
})
|
})
|
||||||
|
|
||||||
// Log response headers for debugging
|
|
||||||
console.log('Response Headers:', response.headers);
|
|
||||||
|
|
||||||
// Forward the status code
|
// Forward the status code
|
||||||
res.status(response.status)
|
res.status(response.status)
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ export default async function handler(
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
if (!db) {
|
if (!db) {
|
||||||
return res.status(500).json({ message: "Database connection failed" });
|
return res.status(500).json({ message: "Database connection failed" });
|
||||||
}
|
}
|
||||||
@@ -34,7 +33,7 @@ export default async function handler(
|
|||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
return res.status(500).json({
|
return res.status(500).json({
|
||||||
message: error.message ||"Internal Server Error",
|
message: error.message ||"Internal Server Error",
|
||||||
error: error,
|
error: error.error || "Internal Server Error",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,8 +1,5 @@
|
|||||||
import { Inter } from "next/font/google";
|
|
||||||
import PeopleList from "@/components/people/PeopleList";
|
import PeopleList from "@/components/people/PeopleList";
|
||||||
|
|
||||||
const inter = Inter({ subsets: ["latin"] });
|
|
||||||
|
|
||||||
export default function Home() {
|
export default function Home() {
|
||||||
return <PeopleList />
|
return <PeopleList />
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user