Added handling for undefined errors and test coverage

Fixes #1827
Merge pull request #1831 from schneidmaster/fix-1827

Added handling for undefined errors and test coverage