generated from nhcarrigan/template
fix: add comprehensive error handling and logging to api and web
Wrap all async API route handlers and services in try/catch blocks, piping errors to the @nhcarrigan/logger telemetry service. Add a frontend logError utility, React ErrorBoundary, and overridden console to forward all unhandled client-side errors to the backend telemetry endpoint.
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
*/
|
||||
|
||||
import { verifyToken } from "../services/jwt.js";
|
||||
import { logger } from "../services/logger.js";
|
||||
import type { HonoEnvironment } from "../types/hono.js";
|
||||
import type { MiddlewareHandler } from "hono";
|
||||
|
||||
@@ -33,7 +34,13 @@ export const authMiddleware: MiddlewareHandler<HonoEnvironment> = async(
|
||||
try {
|
||||
const payload = verifyToken(token);
|
||||
context.set("discordId", payload.discordId);
|
||||
} catch {
|
||||
} catch (error) {
|
||||
void logger.error(
|
||||
"auth_middleware",
|
||||
error instanceof Error
|
||||
? error
|
||||
: new Error(String(error)),
|
||||
);
|
||||
return context.json({ error: "Invalid or expired token" }, 401);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user