fix issue in error handling logic