Skip to content

Commit ec872de

Browse files
committed
fix: improve error messages /last-approved
1 parent 717f857 commit ec872de

File tree

5 files changed

+39
-63
lines changed

5 files changed

+39
-63
lines changed

primitives/src/big_num.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,19 @@ use num_derive::{Num, NumOps, One, Zero};
1010
use serde::{Deserialize, Deserializer, Serialize, Serializer};
1111

1212
#[derive(
13-
Serialize, Deserialize, Debug, Clone, PartialEq, Eq, PartialOrd, Ord, NumOps, One, Zero, Num, Default
13+
Serialize,
14+
Deserialize,
15+
Debug,
16+
Clone,
17+
PartialEq,
18+
Eq,
19+
PartialOrd,
20+
Ord,
21+
NumOps,
22+
One,
23+
Zero,
24+
Num,
25+
Default,
1426
)]
1527
pub struct BigNum(
1628
#[serde(

sentry/src/analytics_recorder.rs

Lines changed: 12 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ use crate::Session;
33
use primitives::sentry::Event;
44
use primitives::sentry::{ChannelReport, PublisherReport};
55
use primitives::{BigNum, Channel};
6-
use redis::pipe;
76
use redis::aio::MultiplexedConnection;
7+
use redis::pipe;
88
use slog::{error, Logger};
99

1010
pub fn get_payout(channel: &Channel, event: &Event) -> BigNum {
@@ -16,7 +16,7 @@ pub fn get_payout(channel: &Channel, event: &Event) -> BigNum {
1616
return click.min;
1717
}
1818
}
19-
19+
2020
Default::default()
2121
}
2222
_ => Default::default(),
@@ -56,23 +56,13 @@ pub async fn record(
5656

5757
if let Some(ad_unit) = ad_unit {
5858
db.zincr(
59-
format!(
60-
"{}:{}:{}",
61-
PublisherReport::AdUnit,
62-
event,
63-
publisher
64-
),
59+
format!("{}:{}:{}", PublisherReport::AdUnit, event, publisher),
6560
ad_unit,
6661
1,
6762
)
6863
.ignore();
6964
db.zincr(
70-
format!(
71-
"{}:{}:{}",
72-
ChannelReport::AdUnit,
73-
event,
74-
publisher
75-
),
65+
format!("{}:{}:{}", ChannelReport::AdUnit, event, publisher),
7666
ad_unit,
7767
1,
7868
)
@@ -81,23 +71,13 @@ pub async fn record(
8171

8272
if let Some(ad_slot) = ad_slot {
8373
db.zincr(
84-
format!(
85-
"{}:{}:{}",
86-
PublisherReport::AdSlot,
87-
event,
88-
publisher
89-
),
74+
format!("{}:{}:{}", PublisherReport::AdSlot, event, publisher),
9075
ad_slot,
9176
1,
9277
)
9378
.ignore();
9479
db.zincr(
95-
format!(
96-
"{}:{}:{}",
97-
PublisherReport::AdSlotPay,
98-
event,
99-
publisher
100-
),
80+
format!("{}:{}:{}", PublisherReport::AdSlotPay, event, publisher),
10181
ad_slot,
10282
pay_amount,
10383
)
@@ -120,40 +100,25 @@ pub async fn record(
120100
}
121101

122102
let hostname = (referrer.as_ref())
123-
.or_else(|| session.referrer_header.as_ref())
124-
.map(|rf| rf.split('/').nth(2).map(ToString::to_string))
125-
.flatten();
103+
.or_else(|| session.referrer_header.as_ref())
104+
.map(|rf| rf.split('/').nth(2).map(ToString::to_string))
105+
.flatten();
126106

127107
if let Some(hostname) = &hostname {
128108
db.zincr(
129-
format!(
130-
"{}:{}:{}",
131-
PublisherReport::Hostname,
132-
event,
133-
publisher
134-
),
109+
format!("{}:{}:{}", PublisherReport::Hostname, event, publisher),
135110
hostname,
136111
1,
137112
)
138113
.ignore();
139114
db.zincr(
140-
format!(
141-
"{}:{}:{}",
142-
ChannelReport::Hostname,
143-
event,
144-
channel.id
145-
),
115+
format!("{}:{}:{}", ChannelReport::Hostname, event, channel.id),
146116
hostname,
147117
1,
148118
)
149119
.ignore();
150120
db.zincr(
151-
format!(
152-
"{}:{}:{}",
153-
ChannelReport::HostnamePay,
154-
event,
155-
channel.id
156-
),
121+
format!("{}:{}:{}", ChannelReport::HostnamePay, event, channel.id),
157122
hostname,
158123
1,
159124
)

sentry/src/db/analytics.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ use crate::db::DbPool;
22
use crate::epoch;
33
use crate::Session;
44
use bb8::RunError;
5+
use bb8_postgres::tokio_postgres::types::ToSql;
56
use chrono::Utc;
67
use primitives::analytics::{AnalyticsData, AnalyticsQuery, ANALYTICS_QUERY_LIMIT};
78
use primitives::sentry::{AdvancedAnalyticsResponse, ChannelReport, PublisherReport};
8-
use bb8_postgres::tokio_postgres::types::{ToSql};
99
use primitives::{ChannelId, ValidatorId};
10-
use redis::cmd;
1110
use redis::aio::MultiplexedConnection;
11+
use redis::cmd;
1212
use std::collections::HashMap;
1313
use std::error::Error;
1414

@@ -69,7 +69,7 @@ pub async fn get_analytics(
6969

7070
where_clauses.extend(vec![
7171
format!("event_type = ${}", params.len()),
72-
format!("{} IS NOT NULL", metric)
72+
format!("{} IS NOT NULL", metric),
7373
]);
7474

7575
if let Some(id) = channel_id {
@@ -80,12 +80,10 @@ pub async fn get_analytics(
8080
let mut select_clause = match analytics_type {
8181
AnalyticsType::Advertiser { session } => {
8282
if channel_id.is_none() {
83-
where_clauses.push(
84-
format!(
85-
"channel_id IN (SELECT id FROM channels WHERE creator = '{}')",
86-
session.uid
87-
)
88-
);
83+
where_clauses.push(format!(
84+
"channel_id IN (SELECT id FROM channels WHERE creator = '{}')",
85+
session.uid
86+
));
8987
}
9088

9189
format!(

sentry/src/routes/analytics.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,8 @@ pub async fn process_analytics<A: Adapter>(
8787

8888
let channel_id = req.extensions().get::<ChannelId>();
8989

90-
let segment_channel = query
91-
.segment_by_channel
92-
.is_some();
93-
90+
let segment_channel = query.segment_by_channel.is_some();
91+
9492
let limit = query.limit;
9593

9694
let aggr = get_analytics(

sentry/src/routes/channel.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,15 @@ pub async fn last_approved<A: Adapter>(
116116

117117
let approve_state = match lastest_approve_state(&app.pool, &channel).await? {
118118
Some(approve_state) => approve_state,
119-
None => return Ok(default_response)
119+
None => return Ok(default_response),
120120
};
121121

122122
let state_root = match approve_state.msg.clone() {
123123
MessageTypes::ApproveState(approve_state) => approve_state.state_root,
124-
_ => return Err(ResponseError::BadRequest("invalid request".to_string())),
124+
_ => {
125+
error!(&app.logger, "{}", "failed to retrieve approved"; "module" => "last_approved");
126+
return Err(ResponseError::BadRequest("an error occured".to_string()));
127+
}
125128
};
126129

127130
let new_state = latest_new_state(&app.pool, &channel, &state_root).await?;

0 commit comments

Comments
 (0)