Update Charges API to Allow Valid Empty Response

API should fail gracefully if an empty response is sent.
Example reason: an API consumer should be able to traverse the pages until empty data is returned.

Note: currently this is not possible, since a generic error will be thrown if the data set is empty (including on a fresh install of TeslaMate) or if there is an invalid charge in the response. It's impossible to know if all data points were traversed or if an error exists on a single charge (See: https://github.com/tobiasehlert/teslamateapi/issues/43)
This commit is contained in:
Alec O'Connor
2021-05-12 17:13:56 -04:00
committed by GitHub
parent 679d2a89e1
commit ed1dc4dbb8
+5
View File
@@ -179,6 +179,11 @@ func TeslaMateAPICarsChargesV1(c *gin.Context) {
if err != nil {
log.Fatal(err)
}
// if no errors, but ChargeData is empty, return a valid response with an empty set
if len(ChargeData) == 0 {
ValidResponse = true
}
//
// build the data-blob