File tree Expand file tree Collapse file tree 2 files changed +29
-4
lines changed
crates/core/tedge/src/cli/http
tests/RobotFramework/tests/tedge Expand file tree Collapse file tree 2 files changed +29
-4
lines changed Original file line number Diff line number Diff line change 11use crate :: cli:: http:: cli:: Content ;
22use crate :: command:: Command ;
33use crate :: log:: MaybeFancy ;
4+ use anyhow:: anyhow;
45use anyhow:: Error ;
56use hyper:: http:: HeaderValue ;
67use reqwest:: blocking;
@@ -74,10 +75,27 @@ impl HttpCommand {
7475 }
7576
7677 fn send ( request : blocking:: RequestBuilder ) -> Result < ( ) , Error > {
77- let http_result = request. send ( ) ?;
78- let mut http_response = http_result. error_for_status ( ) ?;
79- http_response. copy_to ( & mut std:: io:: stdout ( ) ) ?;
80- Ok ( ( ) )
78+ let mut http_result = request. send ( ) ?;
79+ let status = http_result. status ( ) ;
80+ if status. is_success ( ) {
81+ http_result. copy_to ( & mut std:: io:: stdout ( ) ) ?;
82+ Ok ( ( ) )
83+ } else {
84+ let kind = if status. is_client_error ( ) {
85+ "HTTP client error"
86+ } else if status. is_server_error ( ) {
87+ "HTTP server error"
88+ } else {
89+ "HTTP error"
90+ } ;
91+ let error = format ! (
92+ "{kind}: {} {}\n {}" ,
93+ status. as_u16( ) ,
94+ status. canonical_reason( ) . unwrap_or( "" ) ,
95+ http_result. text( ) . unwrap_or( "" . to_string( ) )
96+ ) ;
97+ Err ( anyhow ! ( error) ) ?
98+ }
8199 }
82100}
83101
Original file line number Diff line number Diff line change @@ -43,6 +43,13 @@ Accessing file-transfer from a child device
4343 Execute Command tedge http delete /tedge/file-transfer/target
4444 Execute Command tedge http get /tedge/file-transfer/target exp_exit_code=1
4545
46+ Displaying server errors
47+ ${error_msg } = Execute Command
48+ ... tedge http post /tedge/entity-store/v1/entities '{"@topic-id": "device/a//", "@type": "child-device", "@parent": "device/unknown//"}' 2>&1
49+ ... exp_exit_code=1
50+ Should Contain ${error_msg } 400 Bad Request
51+ Should Contain ${error_msg } Specified parent "device/unknown//" does not exist in the store
52+
4653
4754*** Keywords ***
4855Setup Child Device
You can’t perform that action at this time.
0 commit comments