I added some comments.

Basically data contains either a sessionID or an error. I had one situation starting tests in Appium in which data contained a string and the sessionID was hidden in header.location. So it's important to have the old method as fallback.