From d6e73a9fb4891004b087fa9cf734d6479d4b630a Mon Sep 17 00:00:00 2001 From: Angelo Reale <12191809+angeloreale@users.noreply.github.com> Date: Tue, 27 Aug 2024 03:07:18 +0100 Subject: [PATCH 1/7] ar(fix) bots shield --- src/app/api/v1/user/route.ts | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/app/api/v1/user/route.ts b/src/app/api/v1/user/route.ts index 73a86bf..2e602ae 100644 --- a/src/app/api/v1/user/route.ts +++ b/src/app/api/v1/user/route.ts @@ -22,15 +22,15 @@ const generateErrorResponse = (e: any, status: number) => { // export const dynamic = 'force-static'; export async function POST(request: CombineRequest) { - const healthSecret = - request?.headers?.get('x-dp-keepalive') || - request?.cookies?.toString()?.split('dp-health-check=')[1].split(';')[0] || - request?.headers?.get('cookies')?.toString()?.split('dp-health-check=')[1].split(';')[0] || - ''; - const isHealthCheck = healthSecret === process.env.NEXUS_KEEPALIVE; + try { + const healthSecret = + request?.headers?.get('x-dp-keepalive') || + request?.cookies?.toString()?.split('dp-health-check=')[1]?.split(';')[0] || + request?.headers?.get('cookies')?.toString()?.split('dp-health-check=')[1]?.split(';')[0] || + ''; + const isHealthCheck = healthSecret === process.env.NEXUS_KEEPALIVE; - if (isHealthCheck) { - try { + if (isHealthCheck) { await GetPrivateCommonAbilities({}); return NextResponse.json( { @@ -41,9 +41,9 @@ export async function POST(request: CombineRequest) { status: 200, }, ); - } catch (e) { - return NextResponse.json(generateErrorResponse(e, 403), { status: 403 }); } + } catch (e) { + return NextResponse.json(generateErrorResponse(e, 403), { status: 403 }); } try { From 5df04eed6bcb70a1b9357a7fe3988d07fa5bc12c Mon Sep 17 00:00:00 2001 From: Angelo Reale <12191809+angeloreale@users.noreply.github.com> Date: Tue, 27 Aug 2024 03:10:06 +0100 Subject: [PATCH 2/7] ar(fix) bots shield --- src/app/api/v1/user/route.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/app/api/v1/user/route.ts b/src/app/api/v1/user/route.ts index 2e602ae..fae92db 100644 --- a/src/app/api/v1/user/route.ts +++ b/src/app/api/v1/user/route.ts @@ -14,7 +14,7 @@ type CombineRequest = NextRequest & NextApiRequest; const generateErrorResponse = (e: any, status: number) => { return { ok: false, - status, + status: status || 500, message: `${e?.message}`, }; }; @@ -22,6 +22,7 @@ const generateErrorResponse = (e: any, status: number) => { // export const dynamic = 'force-static'; export async function POST(request: CombineRequest) { + let error; try { const healthSecret = request?.headers?.get('x-dp-keepalive') || @@ -43,7 +44,7 @@ export async function POST(request: CombineRequest) { ); } } catch (e) { - return NextResponse.json(generateErrorResponse(e, 403), { status: 403 }); + error = generateErrorResponse(e, 403); } try { @@ -77,8 +78,10 @@ export async function POST(request: CombineRequest) { return NextResponse.json(generateErrorResponse({ message: 'Code 000: Malformed request' }, 400), { status: 400 }); } catch (e) { - return NextResponse.json(generateErrorResponse(e, 400), { status: 400 }); + error = generateErrorResponse(e, 400); } + + return NextResponse.json(error, error.status); } export async function PATCH(request: CombineRequest) { From e11ce621805b12ac0e632fb99bbcd8e6a32796c3 Mon Sep 17 00:00:00 2001 From: Angelo Reale <12191809+angeloreale@users.noreply.github.com> Date: Tue, 27 Aug 2024 03:13:05 +0100 Subject: [PATCH 3/7] ar(fix) bots shield --- src/app/api/v1/user/route.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/app/api/v1/user/route.ts b/src/app/api/v1/user/route.ts index fae92db..39a6627 100644 --- a/src/app/api/v1/user/route.ts +++ b/src/app/api/v1/user/route.ts @@ -76,9 +76,9 @@ export async function POST(request: CombineRequest) { ); } - return NextResponse.json(generateErrorResponse({ message: 'Code 000: Malformed request' }, 400), { status: 400 }); + error = generateErrorResponse({ message: 'Code 000: Malformed request' }, 400); } catch (e) { - error = generateErrorResponse(e, 400); + error = generateErrorResponse(e, 500); } return NextResponse.json(error, error.status); From 1689748e97afd4bed240a6f3bc66aca3276f2ee9 Mon Sep 17 00:00:00 2001 From: Angelo Reale <12191809+angeloreale@users.noreply.github.com> Date: Tue, 27 Aug 2024 03:13:54 +0100 Subject: [PATCH 4/7] ar(fix) bots shield --- src/app/api/v1/user/route.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/api/v1/user/route.ts b/src/app/api/v1/user/route.ts index 39a6627..54215bf 100644 --- a/src/app/api/v1/user/route.ts +++ b/src/app/api/v1/user/route.ts @@ -81,7 +81,7 @@ export async function POST(request: CombineRequest) { error = generateErrorResponse(e, 500); } - return NextResponse.json(error, error.status); + return NextResponse.json(error, { status: error.status }); } export async function PATCH(request: CombineRequest) { From cecfe57a4cf6e9d1e3ffc111cf3680aced50a5fd Mon Sep 17 00:00:00 2001 From: Angelo Reale <12191809+angeloreale@users.noreply.github.com> Date: Tue, 27 Aug 2024 03:14:46 +0100 Subject: [PATCH 5/7] ar(fix) bots shield --- src/app/api/v1/user/route.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/api/v1/user/route.ts b/src/app/api/v1/user/route.ts index 54215bf..038cea4 100644 --- a/src/app/api/v1/user/route.ts +++ b/src/app/api/v1/user/route.ts @@ -81,7 +81,7 @@ export async function POST(request: CombineRequest) { error = generateErrorResponse(e, 500); } - return NextResponse.json(error, { status: error.status }); + return NextResponse.json(error, { status: error?.status || 500 }); } export async function PATCH(request: CombineRequest) { From 20ab329efe1fde0dcae90c01dbdaf2280f7a9fc7 Mon Sep 17 00:00:00 2001 From: Angelo Reale <12191809+angeloreale@users.noreply.github.com> Date: Tue, 27 Aug 2024 03:17:55 +0100 Subject: [PATCH 6/7] ar(fix) bots shield --- src/app/api/v1/user/route.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/app/api/v1/user/route.ts b/src/app/api/v1/user/route.ts index 038cea4..80f2216 100644 --- a/src/app/api/v1/user/route.ts +++ b/src/app/api/v1/user/route.ts @@ -22,7 +22,7 @@ const generateErrorResponse = (e: any, status: number) => { // export const dynamic = 'force-static'; export async function POST(request: CombineRequest) { - let error; + const response = { error: generateErrorResponse({ message: 'Code 000/0: Non-identified error.' }) }; try { const healthSecret = request?.headers?.get('x-dp-keepalive') || @@ -44,7 +44,7 @@ export async function POST(request: CombineRequest) { ); } } catch (e) { - error = generateErrorResponse(e, 403); + response.error = generateErrorResponse(e, 403); } try { @@ -76,12 +76,12 @@ export async function POST(request: CombineRequest) { ); } - error = generateErrorResponse({ message: 'Code 000: Malformed request' }, 400); + response.error = generateErrorResponse({ message: 'Code 000: Malformed request' }, 400); } catch (e) { - error = generateErrorResponse(e, 500); + response.error = generateErrorResponse(e, 500); } - return NextResponse.json(error, { status: error?.status || 500 }); + return NextResponse.json(response.error, { status: response?.error?.status || 500 }); } export async function PATCH(request: CombineRequest) { From b0311dc685260b48104dfcf4b988651802286f55 Mon Sep 17 00:00:00 2001 From: Angelo Reale <12191809+angeloreale@users.noreply.github.com> Date: Tue, 27 Aug 2024 03:20:40 +0100 Subject: [PATCH 7/7] ar(fix) bots shield --- src/app/api/v1/user/route.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/api/v1/user/route.ts b/src/app/api/v1/user/route.ts index 80f2216..6ff2a17 100644 --- a/src/app/api/v1/user/route.ts +++ b/src/app/api/v1/user/route.ts @@ -22,7 +22,7 @@ const generateErrorResponse = (e: any, status: number) => { // export const dynamic = 'force-static'; export async function POST(request: CombineRequest) { - const response = { error: generateErrorResponse({ message: 'Code 000/0: Non-identified error.' }) }; + const response = { error: generateErrorResponse({ message: 'Code 000/0: Non-identified error.' }, 500) }; try { const healthSecret = request?.headers?.get('x-dp-keepalive') ||