Fixing an issue in the error handling logic