Add error message patterns
Improved code for getting error message