Skip to content

Commit 4c7437f

Browse files
refactor: standardize catch block error naming (#366)
This PR only includes name change of the err to error.
1 parent f1d37b5 commit 4c7437f

20 files changed

Lines changed: 62 additions & 62 deletions

apps/backend/prisma/seed.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,8 @@ async function main() {
142142
}
143143

144144
main()
145-
.catch((e) => {
146-
console.error('❌ Seed failed:', e);
145+
.catch((error) => {
146+
console.error('❌ Seed failed:', error);
147147
process.exit(1);
148148
})
149149
.finally(async () => {

apps/backend/src/app.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ export async function buildApp():Promise<FastifyInstance> {
9191
app.decorate('authenticate', async function (request: any, reply: any) {
9292
try {
9393
await request.jwtVerify();
94-
} catch (_err) {
94+
} catch (error) {
9595
reply.status(401).send({ error: 'Unauthorized' });
9696
}
9797
});

apps/backend/src/plugins/redis.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export const redisPlugin = fp(async (app: FastifyInstance) => {
1717
try {
1818
await redis.connect();
1919
app.log.info('🔴 Redis connected');
20-
} catch (err) {
20+
} catch (error) {
2121
app.log.warn('⚠️ Redis connection failed — running without cache');
2222
}
2323

apps/backend/src/routes/auth.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,8 @@ app.get('/github/callback', async (request: FastifyRequest<{ Querystring: OAuthC
166166
update: { accessToken: encryptedToken, scopes: 'read:user user:email' },
167167
create: { userId: user.id, platform: 'github', accessToken: encryptedToken, scopes: 'read:user user:email' },
168168
});
169-
} catch (err) {
170-
app.log.error({ err, userId: user.id }, 'Failed to persist GitHub OAuth token — authentication proceeds');
169+
} catch (error) {
170+
app.log.error({ error, userId: user.id }, 'Failed to persist GitHub OAuth token — authentication proceeds');
171171
}
172172

173173
// Generate JWT
@@ -192,9 +192,9 @@ app.get('/github/callback', async (request: FastifyRequest<{ Querystring: OAuthC
192192
});
193193

194194
return reply.redirect(`${process.env.PUBLIC_APP_URL}/dashboard`);
195-
} catch (err) {
196-
const message = err instanceof Error ? err.message : String(err);
197-
app.log.error({ err, message }, 'GitHub auth error');
195+
} catch (error) {
196+
const message = error instanceof Error ? error.message : String(error);
197+
app.log.error({ error, message }, 'GitHub auth error');
198198
return reply.status(500).send({ error: 'Authentication failed' });
199199
}
200200
});
@@ -326,9 +326,9 @@ app.get('/github/callback', async (request: FastifyRequest<{ Querystring: OAuthC
326326
});
327327

328328
return reply.redirect(`${process.env.PUBLIC_APP_URL}/dashboard`);
329-
} catch (err) {
330-
const message = err instanceof Error ? err.message : String(err);
331-
app.log.error({ err, message }, 'Google auth error');
329+
} catch (error) {
330+
const message = error instanceof Error ? error.message : String(error);
331+
app.log.error({ error, message }, 'Google auth error');
332332
return reply.status(500).send({ error: 'Authentication failed' });
333333
}
334334
});

apps/backend/src/routes/connect.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,9 @@ export async function connectRoutes(app: FastifyInstance) {
152152

153153
return reply.redirect(`${process.env.PUBLIC_APP_URL}/settings?connected=github`);
154154

155-
} catch (err) {
156-
const message = err instanceof Error ? err.message : String(err);
157-
app.log.error({ err, message }, 'GitHub connect error');
155+
} catch (error) {
156+
const message = error instanceof Error ? error.message : String(error);
157+
app.log.error({ error, message }, 'GitHub connect error');
158158
return reply.redirect(`${process.env.PUBLIC_APP_URL}/settings?error=server_error`);
159159
}
160160
});
@@ -183,7 +183,7 @@ export async function connectRoutes(app: FastifyInstance) {
183183
},
184184
});
185185
return { success: true };
186-
} catch (err) {
186+
} catch (error) {
187187
return reply.status(404).send({ error: 'Connection not found' });
188188
}
189189
});

apps/backend/src/routes/follow.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ export async function followRoutes(app: FastifyInstance) {
131131
},
132132
});
133133
return reply.send({ status: 'success', logId: log.id });
134-
} catch (err: any) {
135-
app.log.error('Failed to log follow:', err);
134+
} catch (error: any) {
135+
app.log.error('Failed to log follow:', error);
136136
return reply.status(500).send({ error: 'Failed to log follow event' });
137137
}
138138
});

apps/backend/src/routes/nfc.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ export async function nfcRoutes(app: FastifyInstance) {
5050
}
5151

5252
username = user.username;
53-
} catch (err) {
53+
} catch (error) {
5454
request.log.error(
55-
{ err },
55+
{ error },
5656
'Failed to fetch user for NFC payload'
5757
);
5858
return reply.status(500).send({
@@ -73,9 +73,9 @@ export async function nfcRoutes(app: FastifyInstance) {
7373
error: 'Card not found',
7474
});
7575
}
76-
} catch (err) {
76+
} catch (error) {
7777
request.log.error(
78-
{ err },
78+
{ error },
7979
'Failed to fetch card for NFC payload'
8080
);
8181
return reply.status(500).send({

apps/backend/src/routes/profiles.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,15 @@ export async function profileRoutes(app: FastifyInstance) {
103103
});
104104

105105
return response;
106-
} catch (err: any) {
106+
} catch (error: any) {
107107
// Unique constraint violation — two concurrent requests raced through the
108108
// findFirst check above and both attempted the write. The DB constraint
109109
// fires on the losing request; surface it as a deterministic 409 rather
110110
// than leaking a raw Prisma error as a 500.
111-
if (err?.code === 'P2002') {
111+
if (error?.code === 'P2002') {
112112
return reply.status(409).send({ error: 'Username already taken' });
113113
}
114-
app.log.error({ err }, 'DB error in PUT /profiles/me');
114+
app.log.error({ error }, 'DB error in PUT /profiles/me');
115115
return reply.status(500).send({ error: 'Internal server error' });
116116
}
117117
});

apps/backend/src/routes/public.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ export async function publicRoutes(app: FastifyInstance) {
129129
viewerAgent: request.headers['user-agent'] || null,
130130
source: request.query?.source || 'link',
131131
},
132-
}).catch((err: unknown) => app.log.error(`Failed to log view: ${getErrorMessage(err)}`));
132+
}).catch((error: unknown) => app.log.error(`Failed to log view: ${getErrorMessage(error)}`));
133133
}
134134

135135
// Fetch viewer's successful follow logs for this profile's links
@@ -295,7 +295,7 @@ export async function publicRoutes(app: FastifyInstance) {
295295
viewerAgent: request.headers['user-agent'] || null,
296296
source: request.query?.source || 'qr',
297297
},
298-
}).catch((err: unknown) => app.log.error(`Failed to log view: ${getErrorMessage(err)}`));
298+
}).catch((error: unknown) => app.log.error(`Failed to log view: ${getErrorMessage(error)}`));
299299
}
300300

301301

@@ -375,8 +375,8 @@ export async function publicRoutes(app: FastifyInstance) {
375375
.header('Content-Type', 'image/png')
376376
.header('Content-Disposition', `inline; filename="devcard-${username}.png"`)
377377
.send(png);
378-
} catch (err) {
379-
app.log.error({ err, username, size, format }, 'QR generation failed');
378+
} catch (error) {
379+
app.log.error({ error, username, size, format }, 'QR generation failed');
380380
return reply.status(500).send({ error: 'QR code generation failed' });
381381
}
382382
});

apps/backend/src/server.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ async function start() {
1010
try {
1111
await app.listen({ port: PORT, host: HOST });
1212
app.log.info(`🚀 DevCard API running at http://${HOST}:${PORT}`);
13-
} catch (err) {
14-
app.log.error(err);
13+
} catch (error) {
14+
app.log.error(error);
1515
process.exit(1);
1616
}
1717
}

0 commit comments

Comments
 (0)