ThingSet / thingset-device-library

ThingSet library for resource-constrained devices written in C/C++
https://thingset.io/thingset-device-library/
Apache License 2.0
13 stars 6 forks source link

Return error instead of invalid JSON if response too large #4

Closed martinjaeger closed 3 years ago

martinjaeger commented 3 years ago

With more data nodes than the buffer can fit, we got following ThingSet response:

Received Request (5 bytes): ?conf
:85 Content. { ... ,"Credit":0,"CustomMessage"}

ThingSet should always answer with valid JSON or an error message.

This commit fixes the issue. Now we get:

Received Request (5 bytes): ?conf
:E1 Response too large.
martinjaeger commented 3 years ago

Strictly speaking this is good. However, I quite liked the previous characteristic where is would strip out the JSON value which is too large and still display the rest of the data. It was really useful in the case where I had a large buffer as a thingset object and when the buffer gets too full, I can still see the rest of the data in that category.

Unfortunately it didn't always strip out the entire JSON key/value pair, but sometimes only the value. This has to be avoided, I think. But we could think about a new error code "partial response" (not sure if this should be considered an error or a success though).

I suggest to merge and open an enhancement issue for the partial success return code.