add conditional check to error logging