I've tested this change and it seems that 'close' event hasn't been fired on 401 auth errors so it probably isn't the best place to check for status codes. When placed inside 'response' callback, it works fine.