extracted logAndSendError as function