Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/api/github/route.error-resilience.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ it('returns 500 for unexpected internal errors', async () => {
expect(response.status).toBe(500);

expect(await response.json()).toEqual({
error: 'Unexpected database failure',
error: 'An unexpected error occurred. Please try again.',
});
});
it('unwraps nested error causes and returns 404', async () => {
Expand Down
4 changes: 2 additions & 2 deletions app/api/github/route.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ describe('Standard route behavior', () => {
const body = await response.json();

expect(response.status).toBe(500);
expect(body.error).toContain('Database offline');
expect(body.error).toBe('An unexpected error occurred. Please try again.');
});

it('returns 500 instead of hanging when an error cause chain is circular', async () => {
Expand All @@ -243,7 +243,7 @@ describe('Standard route behavior', () => {
const body = await response.json();

expect(response.status).toBe(500);
expect(body.error).toBe('Circular cause root');
expect(body.error).toBe('An unexpected error occurred. Please try again.');
});

it('parses valid org parameter and passes it to getFullDashboardData', async () => {
Expand Down
24 changes: 7 additions & 17 deletions app/api/github/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,6 @@ function getSafeRootCause(error: unknown): unknown {
return currentErr;
}

function getSafeErrorMessage(error: unknown): string {
const rootCause = getSafeRootCause(error);

if (rootCause instanceof Error && rootCause.message) {
return rootCause.message;
}

if (error instanceof Error && error.message) {
return error.message;
}

return 'Unknown error';
}

function logSecurityEvent(event: string, details: Record<string, unknown>) {
logger.warn('Security event', {
type: 'SECURITY_EVENT',
Expand Down Expand Up @@ -249,10 +235,14 @@ export async function GET(request: Request) {
);
}

// Default fallback
const errMessage = getSafeErrorMessage(error);
// Default fallback — log full detail server-side; never forward raw error
// strings to callers (fixes: information-leak via unhandled 500 responses).
logger.error('Unhandled error in GET /api/github', { error });

return NextResponse.json({ error: errMessage }, { status: 500 });
return NextResponse.json(
{ error: 'An unexpected error occurred. Please try again.' },
{ status: 500 }
);
} finally {
clearTimeout(timeoutId);
}
Expand Down
3 changes: 3 additions & 0 deletions test_next_request.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { NextRequest } from 'next/server';
const req = new NextRequest('http://localhost', { headers: { 'user-agent': 'test' } });
console.log(req.headers.get('user-agent'));
12,480 changes: 12,480 additions & 0 deletions test_output.log

Large diffs are not rendered by default.

10,783 changes: 10,783 additions & 0 deletions test_output2.log

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions test_request.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const OriginalRequest = globalThis.Request;
globalThis.Request = class extends OriginalRequest {
constructor(input: RequestInfo | URL, init?: RequestInit) {
super(input, init);
if (!this.headers.has('origin') && !this.headers.has('referer')) {
this.headers.set('origin', 'https://commitpulse.vercel.app');
}
}
};
const req = new Request('http://localhost', { method: 'POST' });
console.log(req.headers.get('origin'));
Loading