Skip to content

BE-10: Request Logging & Error Middleware #10

@tecnodeveloper

Description

@tecnodeveloper

Add centralized logging and error handling middleware for better debugging and maintainability.

User Story

Given API requests
When they are processed
Then they should be logged and errors handled consistently

Tasks

  • Create request logging middleware:
    • Log method, URL, timestamp
  • Create error handling middleware:
    • Catch all errors
    • Standardize error response
  • Handle common errors:
    • Validation errors
    • Not found
    • Server errors
  • Integrate middleware into Express app
  • (Optional) Add logging library (e.g., morgan or winston)
  • Add Swagger error response examples

Acceptance Criteria

  • All requests are logged
  • Errors return consistent JSON format
  • Server does not crash on errors
  • Proper HTTP status codes used

Testing Steps

  • Hit any endpoint → check logs
  • Trigger validation error → check response format
  • Trigger server error → verify 500 response

Definition of Done

  • Logging middleware added
  • Error middleware added
  • App handles errors gracefully
  • Code linted and formatted

Metadata

Metadata

Labels

No labels
No labels

Projects

Status

Backlog

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions