-
Notifications
You must be signed in to change notification settings - Fork 85
Closed
Description
Issue: TimelinesController API Responses
Description
The TimelinesController has several issues related to API response consistency, error handling, and best practices. This issue highlights the key problems and suggests improvements.
Problems Identified
1. Inconsistent HTTP Responses
- The API returns
204 No Contentfor operations that modify data (e.g., creating/updating a timeline or stopping a timeline). - A
204status code does not return a response body, making it difficult for API clients to confirm success. - Recommended Approach: Return structured success responses with a
200 OKstatus, including a message indicating the operation's success.
2. Lack of Detailed Error Messages
- If a requested machine or timeline does not exist, the original code only returns
404 Not Foundwithout a meaningful message. - Recommended Approach: Return a structured error response with a
messagefield explaining why the request failed.
3. Missing BadRequest Handling
- The
POSTrequest for creating/updating a timeline does not validate the request body, potentially leading to unhandled exceptions. - Recommended Approach: Add a
BadRequestresponse (400) when the input is invalid or missing required fields.
4. Improper Exception Handling in StopTimeline
- The
StopTimelinemethod does not handle specific exceptions properly. If a timeline is not found, an unhandled exception might be thrown. - Recommended Approach: Use structured exception handling to return
404 Not Foundfor missing timelines and400 Bad Requestfor general errors.
Proposed Fixes
The following improvements would significantly enhance the TimelinesController:
Consistent Success Responses
- All modification operations (
POST,STOP) should return200 OKwith a JSON response:{ "success": true, "message": "Timeline updated successfully" }
Improved Error Handling
404 Not Foundshould include an error message:{ "success": false, "message": "No timelines found for Machine ID: {machineId}" }400 Bad Requestshould be returned when inputs are invalid.
Better Exception Handling in StopTimeline
- Modify the method so that it catches
KeyNotFoundExceptionand returns a404response instead of an unhandled error.
sei-dupdyke
Metadata
Metadata
Assignees
Labels
No labels