Added some error handling logic
Unit testing