Added error handling in controller and tests.