Skip to content

[Backend] error.middleware.ts: replace 'err: any' with 'unknown' + narrowing #635

@ogazboiz

Description

@ogazboiz

Join the discussion on Telegram

Why this matters

backend/src/middleware/error.middleware.ts line 10:

export const errorHandler = (
    err: any,
    req: Request,
    ...

And line 21: err.issues.map((e: any) => ({ ... })).

any here is the typical Express error-handler gotcha. Replacing with unknown and narrowing (err instanceof Error, err instanceof ZodError, err instanceof Prisma.PrismaClientKnownRequestError) tightens the type. The Zod issue mapping should use ZodIssue.

Acceptance criteria

  • Change err: any to err: unknown and narrow before each access
  • Type the inner .map((e: any) => ...) callback as ZodIssue
  • npm run build still passes

Files to touch

  • backend/src/middleware/error.middleware.ts (lines 10, 21)

Out of scope

  • Removing any from app.ts global CORS error handler (separate issue)

Metadata

Metadata

Labels

Stellar WaveIssues in the Stellar wave programbackendBackend related tasksgood first issueGood for newcomersrefactorRefactoring existing code

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions