fis:consistent error handling across modules#698
Open
Faith-okereke wants to merge 1 commit into
Open
Conversation
|
@Faith-okereke Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
Contributor
|
Kindly resolve conflict and fix workflow. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Linked Issue
Closes #609
What does this PR do?
This PR standardises error handling across the entire backend by replacing ad-hoc NestJS built-in exceptions (NotFoundException, ForbiddenException, ConflictException, etc.) with a consistent set of custom exception classes. Three new classes were added to the existing five — InvalidCredentialsException, InvalidTokenException, and RateLimitExceededException — to cover auth and rate-limiting scenarios that previously used raw HttpException. The GlobalExceptionFilter was extended with a Logger so unhandled and 5xx errors are captured with full stack traces. All 26 affected service, controller, guard, and middleware files were updated, and the exception mapping is documented in CLAUDE.md as the authoritative reference for contributors.
Type of change
Pre-merge checklist (required)
Branch & metadata
feature/issue-<N>-<slug>/fix/issue-<N>-<slug>conventiondevelopormain)Code quality & tests
npm run lint:ci— zero ESLint warningsnpm run format:check— Prettier reports no changes needednpm run typecheck— zero TypeScript errorsnpm run test:ci— all tests pass, coverage ≥ 70%.spec.tsunit testsError handling & NestJS best practices
class-validator/class-transformerdecorators and are wired through NestJS pipes (e.g. globalValidationPipeor explicit)any/unknownreaching the domain)BadRequestException,UnauthorizedException,ForbiddenException,NotFoundException) instead of genericErrorLoggeror central logger service) with meaningful, structured messagesAuthGuard, role/permissions guards, custom guards) are applied to all new/modified endpoints where appropriateAPI documentation / Swagger
/api(or Swagger UI) reflects new/changed endpoints correctlyBreaking changes
Breaking change description (if applicable)
Test evidence (required)
node node_modules/jest/bin/jest.js
--testPathPattern="app.exceptions.spec|global-exception.filter.spec"
--no-coverage
Test Suites: 2 passed, 2 total
Tests: 21 passed, 21 total
Custom Exceptions
ResourceNotFoundException
✓ returns 404 with resource name only
✓ returns 404 with resource name and id
✓ accepts numeric id
ForbiddenOperationException
✓ returns 403 with default message
✓ accepts a custom message
ResourceConflictException
✓ returns 409 without field
✓ returns 409 with field
BusinessValidationException
✓ returns 422 with message
ServiceUnavailableException
✓ returns 503 with service name
InvalidCredentialsException
✓ returns 401 with default message
✓ accepts a custom message
InvalidTokenException
✓ returns 401 with default message
✓ accepts a custom message
RateLimitExceededException
✓ returns 429 without retry info
✓ includes retryAfterSeconds when provided
GlobalExceptionFilter
✓ maps HttpException to its status and message
✓ maps unknown errors to 500
✓ maps ResourceNotFoundException to 404
✓ maps ForbiddenOperationException to 403
✓ includes path and timestamp in every response
✓ handles non-Error thrown objects
Commands run locally
Manual / API verification
Screenshots / recordings (if applicable)