Skip to content

Commit 846af75

Browse files
committed
outside status check
1 parent 408155a commit 846af75

3 files changed

Lines changed: 16 additions & 14 deletions

File tree

code/espurna/libs/Http.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class AsyncHttp {
6262
};
6363

6464
using on_connected_f = std::function<void(AsyncHttp*)>;
65-
using on_status_f = std::function<void(AsyncHttp*, uint16_t status)>;
65+
using on_status_f = std::function<bool(AsyncHttp*, uint16_t status)>;
6666
using on_disconnected_f = std::function<void(AsyncHttp*)>;
6767
using on_error_f = std::function<void(AsyncHttp*, const AsyncHttpError&)>;
6868
using on_body_f = std::function<void(AsyncHttp*, uint8_t*, size_t)>;
@@ -174,9 +174,8 @@ class AsyncHttp {
174174
ASYNC_HTTP_DEBUG("log | buf code=%s\n", buf);
175175

176176
unsigned int code = atoi(buf);
177-
if (code != 200) { // 200 OK
178-
ASYNC_HTTP_DEBUG("err | http code=%u\n", code);
179-
if (http->on_status) http->on_status(http, code);
177+
ASYNC_HTTP_DEBUG("info | http code=%u\n", code);
178+
if (http->on_status && !http->on_status(http, code)) {
180179
return;
181180
}
182181

@@ -258,6 +257,7 @@ class AsyncHttp {
258257

259258
client->write(headers.get());
260259
client->write(http->data.c_str());
260+
261261
}
262262

263263
public:

code/espurna/ota_asynctcp.ino

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,12 @@ void _otaOnError(AsyncHttp* http, const AsyncHttpError& error) {
4848
}
4949
}
5050

51-
void _otaOnStatus(AsyncHttp* http, const unsigned int code) {
52-
if (code != 200) {
53-
DEBUG_MSG_P(PSTR("[OTA] HTTP server response code %u\n"), code);
54-
http->client.close(true);
55-
}
51+
bool _otaOnStatus(AsyncHttp* http, const unsigned int code) {
52+
if (code == 200) return true;
53+
54+
DEBUG_MSG_P(PSTR("[OTA] HTTP server response code %u\n"), code);
55+
http->client.close(true);
56+
return false;
5657
}
5758

5859
void _otaClientOnBody(AsyncHttp* http, uint8_t* data, size_t len) {

code/espurna/thinkspeak.ino

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,12 @@ void _tspkOnDisconnected(AsyncHttp* http) {
114114
if (_tspk_tries) --_tspk_tries;
115115
}
116116

117-
void _tspkOnStatus(AsyncHttp* http, const unsigned int code) {
118-
if (code != 200) {
119-
DEBUG_MSG_P(PSTR("[THINGSPEAK] HTTP server response code %u\n"), code);
120-
http->client.close(true);
121-
}
117+
bool _tspkOnStatus(AsyncHttp* http, const unsigned int code) {
118+
if (code == 200) return true;
119+
120+
DEBUG_MSG_P(PSTR("[THINGSPEAK] HTTP server response code %u\n"), code);
121+
http->client.close(true);
122+
return false;
122123
}
123124

124125
void _tspkOnError(AsyncHttp* http, const AsyncHttpError& error) {

0 commit comments

Comments
 (0)