@@ -66,32 +66,48 @@ void TheGamesDb::getSearchResults(QList<GameEntry> &gameEntries,
6666 }
6767 }
6868 QString k = getKey ();
69- QString req = searchUrlPre + k + " &name=" + searchName +
70- " &filter[platform]=" + pIds.join (" ," );
69+ QString req = searchUrlPre % k % " &name=" % searchName %
70+ " &filter[platform]=" % pIds.join (" ," );
7171 netComm->request (req);
72+ qDebug () << req;
7273 q.exec ();
74+ int httpStatus = netComm->getHttpStatus ();
75+ qDebug () << " HTTP status" << httpStatus;
7376 data = netComm->getData ();
74- qDebug () << req;
75-
7677 jsonDoc = QJsonDocument::fromJson (data);
78+ QString apiStatus = jsonDoc.object ()[" status" ].toString ();
79+
80+ if (httpStatus >= 400 ) {
81+ printf (
82+ " \033 [1;31mServer response status %d\033 [0m: Cannot continue! See "
83+ " https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/"
84+ " Status/%d\n " ,
85+ httpStatus, httpStatus);
86+ reqRemaining = 0 ;
87+ if (!apiStatus.isEmpty ()) {
88+ printf (" \033 [1;31mAPI status message\033 [0m: %s\n " ,
89+ apiStatus.toStdString ().c_str ());
90+ }
91+ return ;
92+ }
93+
7794 if (jsonDoc.isEmpty ()) {
7895 return ;
7996 }
8097
81- QString status = jsonDoc.object ()[" status" ].toString ();
82- if (status != " Success" ) {
83- QString code = jsonDoc.object ()[" code" ].toString ();
84- if (code != " 200" ) {
85- printf (" \033 [1;31mServer response HTTP %s: %s\033 [0m\n " ,
86- code.toStdString ().c_str (), status.toStdString ().c_str ());
87- }
98+ if (!apiStatus.isEmpty () && apiStatus != " Success" ) {
99+ printf (" \033 [1;31mAPI status message\033 [0m: %s. Cannot continue...\n " ,
100+ apiStatus.toStdString ().c_str ());
101+ reqRemaining = 0 ;
88102 return ;
89103 }
104+
90105 QJsonObject obj = jsonDoc.object ();
91106 reqRemaining = obj[" extra_allowance" ].toInt ();
92107 if (reqRemaining <= 0 ) {
93108 reqRemaining = obj[" remaining_monthly_allowance" ].toInt ();
94109 }
110+
95111 if (reqRemaining <= 0 )
96112 printf (" \033 [1;31mYou've reached TheGamesdDb's request limit for this "
97113 " month with %s API key.\033 [0m\n " ,
0 commit comments