Skip to content

Commit

Permalink
fix route logs
Browse files Browse the repository at this point in the history
  • Loading branch information
Anchel123 committed Jan 8, 2025
1 parent 9ee6b9f commit 05915c9
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 7 deletions.
1 change: 1 addition & 0 deletions app/api/graph/[graph]/[node]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export async function GET(request: NextRequest, { params }: { params: Promise<{
const result = await graph.query(query, { params: { nodeId } });
return NextResponse.json({ result }, { status: 200 })
} catch (err: unknown) {
console.error(err)
return NextResponse.json({ message: (err as Error).message }, { status: 400 })
}
}
14 changes: 9 additions & 5 deletions app/api/graph/[graph]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export async function DELETE(request: NextRequest, { params }: { params: Promise
return NextResponse.json({ message: `${graphId} graph deleted` })
}
} catch (err: unknown) {
console.error(err)
return NextResponse.json({ message: (err as Error).message }, { status: 400 })
}
}
Expand Down Expand Up @@ -49,14 +50,14 @@ export async function POST(request: NextRequest, { params }: { params: Promise<{
const key = request.nextUrl.searchParams.get("key")
const srcs = await request.json()

if (!key) return console.error("Missing parameter 'key'")
if (!key) console.error("Missing parameter 'key'")

if (!srcs) return console.error("Missing parameter 'srcs'")
if (!srcs) console.error("Missing parameter 'srcs'")

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const socket = (await client.connection).options?.socket as any

if (!socket) return console.error("socket not found")
if (!socket) console.error("socket not found")

const data = {
host: socket.host,
Expand All @@ -66,7 +67,7 @@ export async function POST(request: NextRequest, { params }: { params: Promise<{
openaikey: key,
}

if (!type) return console.error("Missing parameter 'type'")
if (!type) console.error("Missing parameter 'type'")

const res = await securedFetch(`http://localhost:5000/${prepareArg(type!)}`, {
method: "POST",
Expand All @@ -82,6 +83,7 @@ export async function POST(request: NextRequest, { params }: { params: Promise<{

return NextResponse.json({ result }, { status: 200 })
} catch (err: unknown) {
console.error(err)
return NextResponse.json({ message: (err as Error).message }, { status: 400 })
}
}
Expand All @@ -106,6 +108,7 @@ export async function PATCH(request: NextRequest, { params }: { params: Promise<

return NextResponse.json({ data })
} catch (err: unknown) {
console.error(err)
return NextResponse.json({ message: (err as Error).message }, { status: 400 })
}
}
Expand Down Expand Up @@ -135,7 +138,7 @@ export async function GET(request: NextRequest, { params }: { params: Promise<{
const create = request.nextUrl.searchParams.get("create")
const role = request.nextUrl.searchParams.get("role")

if (!query) return console.log("Missing parameter query")
if (!query) return console.error("Missing parameter query")

if (create === "false" && !(await client.list()).some((g) => g === graphId))
return NextResponse.json({}, { status: 200 })
Expand All @@ -150,6 +153,7 @@ export async function GET(request: NextRequest, { params }: { params: Promise<{

return NextResponse.json({ result }, { status: 200 })
} catch (err: unknown) {
console.error(err)
return NextResponse.json({ message: (err as Error).message }, { status: 400 })
}
}
2 changes: 2 additions & 0 deletions app/api/graph/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export async function GET(request: NextRequest) {

return NextResponse.json({ result }, { status: 200 })
} catch (err: unknown) {
console.error(err)
return NextResponse.json({ message: (err as Error).message }, { status: 400 })
}
}
Expand All @@ -45,6 +46,7 @@ export async function POST(request: NextRequest) {
return NextResponse.json({ config }, { status: 200 })
}
} catch (err: unknown) {
console.error(err)
return NextResponse.json({ message: (err as Error).message }, { status: 400 })
}
}
3 changes: 2 additions & 1 deletion app/api/user/[user]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ export async function PATCH(req: NextRequest, { params }: { params: Promise<{ us
const { user: username } = await params
const role = ROLE.get(req.nextUrl.searchParams.get("role") || "")
try {
if (!role) return console.log("Role is missing")
if (!role) return console.error("Role is missing")

await (await client.connection).aclSetUser(username, role)
return NextResponse.json({ message: "User created" }, { status: 200 })
} catch (err: unknown) {
console.error(err)
return NextResponse.json({ message: (err as Error).message }, { status: 400 })
}
}
3 changes: 2 additions & 1 deletion app/api/user/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export async function POST(req: NextRequest) {
return NextResponse.json({ message: `User ${username} already exists` }, { status: 409 })
}
} catch (err: unknown) {
console.error(err)
// Just a workaround for https://github.com/redis/node-redis/issues/2745
}

Expand Down Expand Up @@ -95,7 +96,7 @@ export async function DELETE(req: NextRequest) {

return NextResponse.json({ message: "Users deleted" }, { status: 200 })
} catch (err: unknown) {
console.log(err)
console.error(err)
return NextResponse.json({ message: (err as Error).message }, { status: 400 })
}
}

0 comments on commit 05915c9

Please sign in to comment.