Skip to content

fix: replace generic Error with proper NestJS HTTP exceptions in controllers#102

Open
Mustafa-Shoukat1 wants to merge 1 commit into
rmyndharis:mainfrom
Mustafa-Shoukat1:fix/controllers-use-proper-http-exceptions
Open

fix: replace generic Error with proper NestJS HTTP exceptions in controllers#102
Mustafa-Shoukat1 wants to merge 1 commit into
rmyndharis:mainfrom
Mustafa-Shoukat1:fix/controllers-use-proper-http-exceptions

Conversation

@Mustafa-Shoukat1
Copy link
Copy Markdown

Summary

Multiple controllers (channel, contact, group, label) throw generic JavaScript Error instead of NestJS HTTP exceptions (BadRequestException, NotFoundException). This causes 500 Internal Server Error responses instead of the correct 400/404 status codes that are already documented in the Swagger API specs.

Problem

When a session is not started (e.g., after a phone disconnects per #100), calling any endpoint on these controllers returns:

{
  \"statusCode\": 500,
  \"message\": \"Internal server error\"
}

Instead of the expected:

{
  \"statusCode\": 400,
  \"message\": \"Session is not started\"
}

Similarly, when a resource (channel, contact, group, label) is not found, the API returns 500 instead of 404.

This is inconsistent with:\n- The Swagger @ApiResponse decorators that document 400/404 responses\n- Other controllers/services in the codebase that correctly use NestJS exceptions (e.g., session.service.ts, status.service.ts, webhook.service.ts)

Changes

Backend (4 controllers)

| File | Fix |\n|------|-----|\n| src/modules/channel/channel.controller.ts | throw new Error(...)BadRequestException / NotFoundException |\n| src/modules/contact/contact.controller.ts | throw new Error(...)BadRequestException / NotFoundException |\n| src/modules/group/group.controller.ts | throw new Error(...)BadRequestException / NotFoundException |\n| src/modules/label/label.controller.ts | throw new Error(...)BadRequestException / NotFoundException |\n\n### Dashboard\n\n| File | Fix |\n|------|-----|\n| dashboard/src/services/api.ts | Added missing 'failed' to Session.status union type to match backend SessionStatus enum |\n\n## Related Issues\n\n- Partially addresses #100 — after a session disconnects from the phone, API calls now return proper 400 responses instead of 500\n\n## Testing\n\n- No existing unit tests for these controllers to break\n- Changes are minimal and mechanical (import swap + class swap)\n- Consistent with patterns already used in status.service.ts, webhook.service.ts, session.service.ts"}

…rollers

Multiple controllers (channel, contact, group, label) throw generic
JavaScript `Error` instead of NestJS HTTP exceptions. This causes 500
Internal Server Error responses instead of the correct 400/404 status
codes documented in Swagger.

Changes:
- channel.controller.ts: Use BadRequestException for "session not started"
  and NotFoundException for "channel not found"
- contact.controller.ts: Use BadRequestException for "session not started"
  and NotFoundException for "contact not found"
- group.controller.ts: Use BadRequestException for "session not started"
  and NotFoundException for "group not found"
- label.controller.ts: Use BadRequestException for "session not started"
  and NotFoundException for "label not found"
- dashboard/src/services/api.ts: Add missing 'failed' status to Session
  type to match backend SessionStatus enum

This also relates to issue rmyndharis#100 — when a session disconnects from the
phone, the engine is destroyed and subsequent API calls return 500
instead of a proper 400 Bad Request.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant