Review comment

This commit is contained in:
jpirnay
2026-04-13 11:38:52 +02:00
parent 03b3e1e5b7
commit 398a25c417
2 changed files with 14 additions and 4 deletions
+12 -3
View File
@@ -383,14 +383,14 @@ KOReaderSyncClient::Error KOReaderSyncClient::authenticate() {
// Skip leading whitespace before checking for '{' so servers that emit // Skip leading whitespace before checking for '{' so servers that emit
// a BOM or indent their JSON don't get incorrectly rejected. // a BOM or indent their JSON don't get incorrectly rejected.
if (!activeBuf->data) { if (!activeBuf->data) {
return SERVER_ERROR; return INVALID_RESPONSE;
} }
const char* p = activeBuf->data; const char* p = activeBuf->data;
while (*p == ' ' || *p == '\t' || *p == '\r' || *p == '\n') { while (*p == ' ' || *p == '\t' || *p == '\r' || *p == '\n') {
p++; p++;
} }
if (*p != '{') { if (*p != '{') {
return SERVER_ERROR; return INVALID_RESPONSE;
} }
return OK; return OK;
} }
@@ -585,7 +585,7 @@ KOReaderSyncClient::Error KOReaderSyncClient::updateProgress(const KOReaderProgr
p++; p++;
} }
if (*p != '\0' && *p != '{') { if (*p != '\0' && *p != '{') {
return SERVER_ERROR; return INVALID_RESPONSE;
} }
} }
return OK; return OK;
@@ -622,6 +622,13 @@ const char* KOReaderSyncClient::lastFailureDetail() {
} }
return g_failureDetailBuf; return g_failureDetailBuf;
} }
// Invalid-response case: HTTP 200/202 but body was not JSON (e.g. captive portal HTML).
// On real success callers never reach lastFailureDetail(), so a 2xx here means INVALID_RESPONSE.
if ((lastHttpCode == 200 || lastHttpCode == 202) && lastEspError == ESP_OK) {
snprintf(g_failureDetailBuf, sizeof(g_failureDetailBuf),
"%s: expected JSON but received HTML (captive portal or proxy?)", lastOperation);
return g_failureDetailBuf;
}
// Server case: got an HTTP status the client didn't recognize as success. // Server case: got an HTTP status the client didn't recognize as success.
if (lastHttpCode != 0) { if (lastHttpCode != 0) {
snprintf(g_failureDetailBuf, sizeof(g_failureDetailBuf), "%s: HTTP %d", lastOperation, lastHttpCode); snprintf(g_failureDetailBuf, sizeof(g_failureDetailBuf), "%s: HTTP %d", lastOperation, lastHttpCode);
@@ -654,6 +661,8 @@ const char* KOReaderSyncClient::errorString(Error error) {
return "Registration is disabled on this server"; return "Registration is disabled on this server";
case REDIRECT_ERROR: case REDIRECT_ERROR:
return "Server redirected (check server URL)"; return "Server redirected (check server URL)";
case INVALID_RESPONSE:
return "Unexpected response (check server URL)";
default: default:
return "Unknown error"; return "Unknown error";
} }
+2 -1
View File
@@ -40,7 +40,8 @@ class KOReaderSyncClient {
NOT_FOUND, NOT_FOUND,
USER_EXISTS, USER_EXISTS,
REGISTRATION_DISABLED, REGISTRATION_DISABLED,
REDIRECT_ERROR REDIRECT_ERROR,
INVALID_RESPONSE
}; };
/** /**