Request flow
Route validation and services throw exceptions.ExceptionsModule.forRoot()
registers the single global AppExceptionsFilter, which delegates serialization
to AllExceptionsFilter. Feature modules register AppException mappings through
ExceptionsModule.forFeature(). Do not register another catch-all filter in
main.ts: doing so previously bypassed those mappings.
All HTTP failures have statusCode, a readable string message, data (details
or null), and error. DTO validation returns 400, errorCode: 10000, and the
individual messages in data and reasons. Native Nest message arrays become a
joined summary plus a data array. Zod errors retain their field/message/code
objects in errors and data. Expired-token responses retain status 498,
application code 10198 and optional expiredAt. Cooldown and account-linking
metadata is preserved.
The public integration guide is in the docs repository at
api-reference/errors.mdx. Frontends can display message directly. Clients
that turn responses into plain Error objects must retain structured response
data separately if they need field errors or cooldown UI.
Writing service errors
- Use
BadRequestExceptionfor invalid requests,ForbiddenExceptionfor denied access andNotFoundExceptionfor missing resources. Do not throw a genericErrorfor expected user-facing failures. - Preserve typed exceptions through catch blocks. Do not convert every failure to 400 or 500, or infer status from words in an error message.
- Register custom
AppExceptionmappings in the owning module. An unmapped application exception remains an internal failure. - Keep unexpected infrastructure failures as server errors. Do not expose raw
provider errors, SQL, credentials or stacks in an
HttpExceptionresponse. The filter logs unexpected failures and sends a generic message. - Validators must handle missing and incorrectly typed input without throwing. The password validator now checks the type before reading its length.
Verification
Fromserver, run:
- Submit a weak, missing and mismatched password to registration, reset-password and change-password routes. Expect 400 and a readable message in the frontend.
- Submit valid data to confirm successful behavior is unchanged.
- Exercise invalid authentication, expired tokens, forbidden operations, missing resources, cooldowns and rate limits; verify status and metadata.
- Trigger a controlled upstream outage in a test environment. Expect a server error without internal details, and a useful server log.