Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle correctly failed downloads (#11456)
Hyper is not opinionated enough to care about connection StatusCode. In case of errors such as AccessDenied, return code 403, it will still download the return body and not raise any errors (see #7121). status_code.is_success checks if status is within 200-299. ``` nearcore/target/debug/neard --home ".near" init --chain-id inexistent_network --download-genesis --download-config 2024-06-01T18:23:34.118646Z INFO neard: version="trunk" build="1.36.1-671-g99a05c482" latest_protocol=67 2024-06-01T18:23:34.121032Z INFO near: Downloading config file from: https://s3-us-west-1.amazonaws.com/build.nearprotocol.com/nearcore-deploy/inexistent_network/config.json ... Error: Failed to initialize configs Caused by: 0: Failed to download the config file from https://s3-us-west-1.amazonaws.com/build.nearprotocol.com/nearcore-deploy/inexistent_network/config.json 1: Unsuccessful HTTP connection. Return code: 403 Forbidden ``` Unit test to make sure non successful codes are handled: ``` cargo test --package nearcore --lib download_file::tests::test_file_download_bad_http_code Finished `test` profile [unoptimized + debuginfo] target(s) in 0.33s warning: the following packages contain code that will be rejected by a future version of Rust: fs_extra v1.2.0, wasmparser v0.78.2 note: to see what the problems were, use the option `--future-incompat-report`, or run `cargo report future-incompatibilities --id 52` Running unittests src/lib.rs (target/debug/deps/nearcore-9131a198eca62608) running 1 test test download_file::tests::test_file_download_bad_http_code ... ok test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 24 filtered out; finished in 0.00s ``` #7122
- Loading branch information