fix(esp_https_ota): only do ota when http status code is 200 (GIT8266O-842) #1265
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
A status code of 404 (Not Found) returned from the OTA server causes the esp8266 to continue to write to the partition until it encounters an error of "OTA image has invalid magic byte (expected 0xE9, saw 0xXX)". This is somewhat ridiculous. HTTP StatusCode should be the first thing that we should do to check its content is right or not, not the Magic after reading some body. If the status code isn't OK, we should just simply drop the body (not read anything).
As for the code of esp-idf, it should also be better that we first check if the code is HttpStatus_OK, then any others. Processing non-OK HTTP error codes is sometimes optional. They exist for providing more debugging information (except for Redirections. Or maybe not, some implementations give us on option automatically do the redirections for us, not everybody who uses it).
https://github.com/espressif/esp-idf/blob/master/components/esp_https_ota/src/esp_https_ota.c#L93-L135