Skip to content

Commit 1c2d841

Browse files
authored
Misc fixes (#97)
* Use raw string literals * Use recommended error message style
1 parent 526e843 commit 1c2d841

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

src/metrics.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,34 +11,34 @@ lazy_static! {
1111
pub static ref INCOMING_REQUESTS: IntCounterVec = IntCounterVec::new(
1212
Opts::new("incoming_requests", "The number of HTTP requests received"),
1313
&["http_method", "path"]
14-
).expect("Prometheus metric initialization failed");
14+
).expect("Prometheus metric options should be valid");
1515
// Request counter by status code
1616
pub static ref RESPONSE_CODE_COLLECTOR: IntCounterVec = IntCounterVec::new(
1717
Opts::new("outgoing_response", "The number of responses sent"),
1818
&["status_code", "http_method", "path"]
19-
).expect("Prometheus metric initialization failed");
19+
).expect("Prometheus metric options should be valid");
2020
// Response histogram by response time
2121
pub static ref RESPONSE_TIME_COLLECTOR: HistogramVec = HistogramVec::new(
2222
HistogramOpts{
2323
common_opts: Opts::new("response_time", "The time taken to respond to each request"),
2424
buckets: prometheus::DEFAULT_BUCKETS.to_vec(), // Change buckets here if desired
2525
},
2626
&["status_code", "http_method", "path"],
27-
).expect("Prometheus metric initialization failed");
27+
).expect("Prometheus metric options should be valid");
2828
}
2929

3030
/// Registers various prometheus metrics with the global registry
3131
pub fn register_metrics() {
3232
let registry = prometheus::default_registry();
3333
registry
3434
.register(Box::new(INCOMING_REQUESTS.clone()))
35-
.expect("registering prometheus metrics during initialization failed");
35+
.expect("Prometheus metrics registration should not fail during initialization");
3636
registry
3737
.register(Box::new(RESPONSE_CODE_COLLECTOR.clone()))
38-
.expect("registering prometheus metrics during initialization failed");
38+
.expect("Prometheus metrics registration should not fail during initialization");
3939
registry
4040
.register(Box::new(RESPONSE_TIME_COLLECTOR.clone()))
41-
.expect("registering prometheus metrics during initialization failed");
41+
.expect("Prometheus metrics registration should not fail during initialization");
4242
}
4343

4444
/// Returns currently gathered prometheus metrics

src/validated_json.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ mod tests {
9090

9191
#[tokio::test]
9292
async fn ok() {
93-
let body = Body::from("{\"foo\": \"abc\", \"bar\": 123}");
93+
let body = Body::from(r#"{"foo": "abc", "bar": 123}"#);
9494
let response = request(body).await;
9595

9696
assert_eq!(response.status(), StatusCode::OK);
@@ -113,7 +113,7 @@ mod tests {
113113

114114
#[tokio::test]
115115
async fn invalid_foo_type() {
116-
let body = Body::from("{\"foo\": 123}");
116+
let body = Body::from(r#"{"foo": 123}"#);
117117
let response = request(body).await;
118118

119119
assert_eq!(response.status(), StatusCode::BAD_REQUEST);
@@ -125,7 +125,7 @@ mod tests {
125125

126126
#[tokio::test]
127127
async fn invalid_foo_too_short() {
128-
let body = Body::from("{\"foo\": \"\"}");
128+
let body = Body::from(r#"{"foo": ""}"#);
129129
let response = request(body).await;
130130

131131
assert_eq!(response.status(), StatusCode::BAD_REQUEST);
@@ -139,7 +139,7 @@ mod tests {
139139

140140
#[tokio::test]
141141
async fn invalid_foo_too_long() {
142-
let body = Body::from("{\"foo\": \"abcd\"}");
142+
let body = Body::from(r#"{"foo": "abcd"}"#);
143143
let response = request(body).await;
144144

145145
assert_eq!(response.status(), StatusCode::BAD_REQUEST);

0 commit comments

Comments
 (0)