BE
Domain: Coding
Difficulty: Beginner
Description:
The actorSearch() function in src/controllers/actorsController.ts lacks error handling. It needs:
- Better error messages for missing or empty name parameter
- Try-catch blocks to handle Wikidata API failures gracefully
- Proper HTTP status codes (400 for bad request, 500 for server error, 204 for no results)
- Validation to ensure the name parameter is not just whitespace
- Logging for debugging failed requests
Expected Outcome:
- Robust error handling in all endpoints
- Informative error messages returned to the frontend
- Proper HTTP status codes
- No unhandled promise rejections
- Server doesn't crash on invalid requests
Setup Steps:
- Clone https://gitlab.wikimedia.org/toolforge-repos/wdtmcollab-api
- Navigate to src/controllers/actorsController.ts.
- Review the actorSearch() function
- Add parameter validation (non-null, non-empty, trim whitespace)
- Enhance error messages to be more specific
- Test with curl or Postman:
- Missing name parameter
- Empty name parameter
- Valid actor name
- Check the console for proper logging
Links/References:
- File: src/controllers/actorsController.ts
- Related service: src/services/actorsService.ts.
- Frontend integration: endpoints.ts in frontend
- Testing tools: Postman, curl, VS Code REST Client