Skip to content

Commit 2df5bd6

Browse files
committed
Added error message back to streaming imp
1 parent 2bf3a4f commit 2df5bd6

File tree

1 file changed

+39
-31
lines changed

1 file changed

+39
-31
lines changed

Diff for: Firebase.cpp

+39-31
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,40 @@ FirebaseEventStream Firebase::stream(const String& path) {
5858
return FirebaseEventStream(host_, auth_, path);
5959
}
6060

61+
/* FirebaseCall */
62+
63+
FirebaseCall::FirebaseCall(const String& host, const String& auth,
64+
const char* method, const String& path, const String& value,
65+
HTTPClient* http) : http_(http) {
66+
const String url = makeUrl(path, auth);
67+
http_->begin(host.c_str(), kFirebasePort, url.c_str(), true, kFirebaseFingerprint);
68+
status_ = http_->sendRequest(method, (uint8_t*)value.c_str(), value.length());
69+
if (isError()) {
70+
error_message_ = String(method) + " " + url + ": " + HTTPClient::errorToString(status_);
71+
}
72+
}
73+
74+
FirebaseCall::FirebaseCall(const String& host, const String& auth,
75+
const char* method, const String& path,
76+
HTTPClient* http) : FirebaseCall(host, auth, method, path, "", http) {
77+
}
78+
79+
bool FirebaseCall::isOk() const {
80+
return status_ == HTTP_CODE_OK;
81+
}
82+
83+
bool FirebaseCall::isError() const {
84+
return status_ < 0;
85+
}
86+
87+
String FirebaseCall::errorMessage() const {
88+
return error_message_;
89+
}
90+
91+
String FirebaseCall::rawResponse() {
92+
return http_->getString();
93+
}
94+
6195
/* FirebaseEventStream */
6296

6397
FirebaseEventStream::FirebaseEventStream(const String& host, const String& auth,
@@ -81,6 +115,11 @@ FirebaseEventStream::FirebaseEventStream(const String& host, const String& auth,
81115
http_.begin(location, kFirebaseFingerprint);
82116
status_ = http_.sendRequest("GET", (uint8_t*)NULL, 0);
83117
}
118+
119+
if (status_ != 200) {
120+
error_message_ = "stream " + location + ": "
121+
+ HTTPClient::errorToString(status_);
122+
}
84123
}
85124

86125
bool FirebaseEventStream::connected() {
@@ -115,35 +154,4 @@ String FirebaseEventStream::errorMessage() const {
115154
return error_message_;
116155
}
117156

118-
/* FirebaseCall */
119-
FirebaseCall::FirebaseCall(const String& host, const String& auth,
120-
const char* method, const String& path, const String& value,
121-
HTTPClient* http) : http_(http) {
122-
const String url = makeUrl(path, auth);
123-
http_->begin(host.c_str(), kFirebasePort, url.c_str(), true, kFirebaseFingerprint);
124-
status_ = http_->sendRequest(method, (uint8_t*)value.c_str(), value.length());
125-
if (isError()) {
126-
error_message_ = String(method) + " " + url + ": " + HTTPClient::errorToString(status_);
127-
}
128-
}
129157

130-
FirebaseCall::FirebaseCall(const String& host, const String& auth,
131-
const char* method, const String& path,
132-
HTTPClient* http) : FirebaseCall(host, auth, method, path, "", http) {
133-
}
134-
135-
bool FirebaseCall::isOk() const {
136-
return status_ == HTTP_CODE_OK;
137-
}
138-
139-
bool FirebaseCall::isError() const {
140-
return status_ < 0;
141-
}
142-
143-
String FirebaseCall::errorMessage() const {
144-
return error_message_;
145-
}
146-
147-
String FirebaseCall::rawResponse() {
148-
return http_->getString();
149-
}

0 commit comments

Comments
 (0)