Skip to content

Commit 4d0ef66

Browse files
authored
[SDS-1412] Richer error string on HTTP Failure (#262)
1 parent b9f1e58 commit 4d0ef66

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

sds-go/go/scanner_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ func TestThirdPartyActiveChecker(t *testing.T) {
554554
ReplacementType: ReplacementTypeNone,
555555
EndIndexExclusive: 51,
556556
ShiftOffset: 0,
557-
MatchStatus: MatchStatus("Error(Error making HTTP request: error sending request for url (https://api.example.com/validate))"), // Full error message from HTTP validation
557+
MatchStatus: MatchStatus("Error(Error making HTTP request: error sending request for url (https://api.example.com/validate): connect error: client error (Connect))"), // Full error message from HTTP validation
558558
}},
559559
},
560560
}

sds/src/match_validation/http_validator.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use crate::{MatchStatus, RuleMatch, match_validation::config::HttpMethod};
88
use ahash::AHashMap;
99
use lazy_static::lazy_static;
1010
use reqwest::blocking::Response;
11+
use std::error::Error as StdError;
1112
use std::{fmt, ops::Range, time::Duration};
1213

1314
lazy_static! {
@@ -135,10 +136,19 @@ impl MatchValidator for HttpValidator {
135136
self.handle_reqwest_response(match_status, &val);
136137
}
137138
Err(err) => {
138-
// TODO(trosenblatt) emit a metrics for this
139-
*match_status = MatchStatus::Error(fmt::format(format_args!(
140-
"Error making HTTP request: {err}"
141-
)));
139+
let mut msg = format!("Error making HTTP request: {err}");
140+
if err.is_timeout() {
141+
msg.push_str(": timeout");
142+
} else if err.is_connect() {
143+
msg.push_str(": connect error");
144+
}
145+
if let Some(status) = err.status() {
146+
msg.push_str(format!(": status {}", status.as_u16()).as_str());
147+
}
148+
if let Some(source) = StdError::source(&err) {
149+
msg.push_str(format!(": {}", source).as_str());
150+
}
151+
*match_status = MatchStatus::Error(msg);
142152
}
143153
}
144154
},

0 commit comments

Comments
 (0)