Handle and log all server errors
Add tests for error handling