fix: replace generic Error with proper NestJS HTTP exceptions in controllers#102
Open
Mustafa-Shoukat1 wants to merge 1 commit into
Open
Conversation
…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.
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.
Summary
Multiple controllers (
channel,contact,group,label) throw generic JavaScriptErrorinstead 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
@ApiResponsedecorators 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'toSession.statusunion type to match backendSessionStatusenum |\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 instatus.service.ts,webhook.service.ts,session.service.ts"}