Using Postman Agent Mode to Add Error Handling to Medicotest API
The Prompt I Ran
Prompt: “Add detailed 4xx and 5xx error responses to each endpoint in this collection (Get clear and consistent error responses for your API endpoints)”
What I Ran It On
Project Context: I’m building Medicotest - a healthcare platform where patients in India (especially Punjab) can upload medical reports (blood tests, X-rays, ultrasounds) and receive:
- AI-powered health diagnoses
- Affordable doctor recommendations (₹400-₹1500 consultation fees)
- Treatment plans with medicine costs
- Location-based doctor search
- Appointment booking
The API has 37 endpoints across 7 categories:
- User Management (5 endpoints)
- Medical Reports Upload (7 endpoints)
- AI Diagnosis (5 endpoints)
- Doctor Discovery (7 endpoints)
- Treatment Plans (3 endpoints)
- Appointment Booking (7 endpoints)
- Health Tips (3 endpoint)
What the Agent Handled
Before Agent Mode
I had built all 37 endpoints with basic functionality:
app.get('/api/users/:id', (req, res) => {
const user = users.find(u => u.id === parseInt(req.params.id));
if (!user) {
return res.status(404).json({
success: false,
message: 'User not found'
});
}
res.json({ success: true, data: user });
});
My error handling was:
- Inconsistent across endpoints
- Missing detailed error messages
- No validation error details
- Generic 500 errors
- No input validation messages
- Missing error codes
After Running the Prompt
The Postman Agent Mode automatically:
-
Added Comprehensive 4xx Errors for all 18 endpoints:
400 Bad Request - Missing required fields with field-specific messages
401 Unauthorized - Authentication errors (for future auth implementation)
403 Forbidden - Permission denied scenarios
404 Not Found - Resource not found with specific resource type
409 Conflict - Duplicate resource conflicts
422 Unprocessable Entity - Validation failures with details
-
Added Detailed 5xx Errors:
500 Internal Server Error - With proper error logging
503 Service Unavailable - For database connection issues
-
Standardized Error Response Format:
{
"success": false,
"error": {
"code": "RESOURCE_NOT_FOUND",
"message": "User with ID 999 not found",
"statusCode": 404,
"timestamp": "2026-01-29T10:30:00.000Z",
"path": "/api/users/999"
}
}
- Added Validation Error Details:
{
"success": false,
"error": {
"code": "VALIDATION_ERROR",
"message": "Invalid input data",
"statusCode": 400,
"details": [
{
"field": "email",
"message": "Invalid email format"
},
{
"field": "phone",
"message": "Phone number must be 10 digits"
}
]
}
}
-
Enhanced Specific Endpoints:
User Registration (POST /api/users):
- Added: Missing email validation
- Added: Duplicate email check (409 Conflict)
- Added: Invalid phone format validation
- Added: Age range validation
Medical Report Upload (POST /api/reports):
- Added: File size limit errors
- Added: Unsupported file type errors (422)
- Added: Missing userId validation
- Added: Invalid reportType validation
Doctor Search (GET /api/doctors):
- Added: Invalid query parameter errors
- Added: Invalid maxFee format validation
- Added: Location not supported errors
Appointment Booking (POST /api/appointments):
- Added: Date validation (past date errors)
- Added: Time slot unavailable (409 Conflict)
- Added: Doctor not available errors
- Added: Double booking prevention
-
Added Error Examples to each endpoint’s documentation with:
- Sample error request
- Expected error response
- HTTP status code
- Error code reference
What I Didn’t Have to Do Anymore
Manual Work Eliminated
Before Agent Mode (Manual Process):
- Identify all possible error scenarios for 37 endpoints (2-3 hours)
- Write error handling code for each scenario (4-5 hours)
- Create a consistent error response format (1 hour)
- Add validation logic for each field (3-4 hours)
- Document error responses in Postman (2-3 hours)
- Test each error scenario manually (3-4 hours)
- Update error messages for consistency (1-2 hours)
Total Manual Time: ~16-22 hours
With Agent Mode: 15 minutes
- Type the prompt
- Agent analyzes all 37 endpoints
- Agent adds comprehensive error handling
- Agent updates documentation
- Ready to test!
Why This Matters for Medicotest
Medicotest will serve vulnerable populations who need:
- Clear error messages in understandable language
- Guidance when upload fails (file size, format)
- Helpful feedback for form validation
- Confidence that their data is being handled properly
Without Proper Errors:
User uploads 15MB X-ray image
Response: "Error 500"
Result: User confused, thinks platform is broken, gives up
With Agent Mode-Enhanced Errors:
User uploads 15MB X-ray image
Response: {
"error": {
"code": "FILE_TOO_LARGE",
"message": "Image size exceeds 10MB limit. Please compress your image.",
"statusCode": 413,
"details": {
"maxSize": "10MB",
"receivedSize": "15MB",
"suggestion": "Try using image compression tools or reduce image quality"
}
}
}
Result: User understands the issue, compresses the image, and successfully uploads
Final Thoughts
As a solo developer building Medicotest to help people access affordable healthcare, Agent Mode has been a game-changer.
Agent Mode didn’t just save time - it elevated the quality of my API to enterprise standards. For a healthcare platform where clear communication can literally help people get the care they need, this is invaluable.