@@ -163,12 +163,14 @@ bool ChatBotHelper::DoRequest(std::string& response, const std::string request,
163163 {
164164 curl_easy_cleanup (curl);
165165 curl_slist_free_all (headers);
166- logprintf (" \n\n Chat Bot Request Failed! Error: %s\n " , exc.what ());
166+
167+ logprintf (" [ChatBot Plugin]: Request Parsing Failed! Error: %s" , exc.what ());
168+
167169 return false ;
168170 }
169171 }
170172 else
171- logprintf (" \n\n Chat Bot Request Failed! Error: %s\n " , curl_easy_strerror (res));
173+ logprintf (" [ChatBot Plugin]: Failed! Error: %s\n " , curl_easy_strerror (res));
172174
173175 curl_easy_cleanup (curl);
174176 curl_slist_free_all (headers);
@@ -189,17 +191,9 @@ std::string ChatBotHelper::GetBotAnswer(const ChatBotParams& params, nlohmann::j
189191 {
190192 std::string answer;
191193
192- try
193- {
194- nlohmann::json error = response.at (" error" );
195-
196- if (!error.empty ())
197- return response.dump (4 ).c_str ();
198- }
199- catch (...)
200- {
201- // errore non trovato
202- }
194+ // controllo errori
195+ if (response.contains (" error" ))
196+ return response.dump (4 ).c_str ();
203197
204198 switch (params.botType )
205199 {
@@ -218,8 +212,8 @@ std::string ChatBotHelper::GetBotAnswer(const ChatBotParams& params, nlohmann::j
218212 }
219213 catch (std::exception &exc)
220214 {
221- logprintf (" ChatBot Plugin Exception GetBotAnswer(): %s\n " , exc.what ());
222- logprintf (" Chatbot Plugin Exception Response:\n %s" , response.dump (4 ).c_str ());
215+ logprintf (" [ ChatBot Plugin]: Exception GetBotAnswer(): %s\n " , exc.what ());
216+ logprintf (" [ChatBot Plugin]: Exception Response:\n %s" , response.dump (4 ).c_str ());
223217
224218 return response.dump (4 ).c_str ();
225219 }
0 commit comments