From d7f3e5f21e99e24078a1396c78e96eb2e7862225 Mon Sep 17 00:00:00 2001 From: Hakusai Zhang Date: Mon, 15 Apr 2024 00:13:32 +0800 Subject: [PATCH] fix(AliNLS): crash when refresh token error. We haven't deal with Ali API return error to us, so get data from json cause program crash. Signed-off-by: Hakusai Zhang --- src/builder/ASR/AliNLSBuilder.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/builder/ASR/AliNLSBuilder.cpp b/src/builder/ASR/AliNLSBuilder.cpp index a1966d8..313268e 100644 --- a/src/builder/ASR/AliNLSBuilder.cpp +++ b/src/builder/ASR/AliNLSBuilder.cpp @@ -157,12 +157,17 @@ void AliNLSBuilder::refreshToken() QJsonObject jsonObject = QJsonDocument::fromJson(QByteArray::fromStdString(resp.text)) .object(); - token = jsonObject.find("Token") - .value() - .toObject() - .find("Id") - .value() - .toString(); + auto tokenIter = jsonObject.find("Token"); + if (tokenIter == jsonObject.end()) { + token = ""; + blog(LOG_WARNING, "Token error, resp: %s", resp.text.c_str()); + } else { + token = tokenIter.value() + .toObject() + .find("Id") + .value() + .toString(); + } qDebug() << "Token:" << token; needRefresh = false; }