added a null check for the intent in error handling