Page MenuHomePhabricator

Add Error Handling and Validation to Actor Search
Closed, ResolvedPublic

Description

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:

  1. Clone https://gitlab.wikimedia.org/toolforge-repos/wdtmcollab-api
  2. Navigate to src/controllers/actorsController.ts.
  3. Review the actorSearch() function
  4. Add parameter validation (non-null, non-empty, trim whitespace)
  5. Enhance error messages to be more specific
  6. Test with curl or Postman:
    • Missing name parameter
    • Empty name parameter
    • Valid actor name
  7. 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