Skip to content

Commit 91377ad

Browse files
committed
sentry - fix merge issues and rename UnAuthorized to Unauthorized to align with the HTTP status responses
1 parent ad5cd8f commit 91377ad

File tree

2 files changed

+14
-21
lines changed

2 files changed

+14
-21
lines changed

sentry/src/lib.rs

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ async fn auth_required_middleware<A: Adapter>(
6868
if req.extensions().get::<Session>().is_some() {
6969
Ok(req)
7070
} else {
71-
Err(ResponseError::UnAuthorized)
71+
Err(ResponseError::Unauthorized)
7272
}
7373
}
7474

@@ -219,14 +219,14 @@ async fn channels_router<A: Adapter>(
219219

220220
// example with middleware
221221
// @TODO remove later
222-
let req = match chain(req, &app, vec![config_middleware]).await {
222+
let req = match chain(req, app, vec![config_middleware]).await {
223223
Ok(req) => req,
224224
Err(error) => {
225225
return Err(error);
226226
}
227227
};
228228

229-
last_approved(req, &app).await
229+
last_approved(req, app).await
230230
} else if let (Some(caps), &Method::GET) =
231231
(CHANNEL_STATUS_BY_CHANNEL_ID.captures(&path), method)
232232
{
@@ -235,14 +235,14 @@ async fn channels_router<A: Adapter>(
235235
.map_or("".to_string(), |m| m.as_str().to_string())]);
236236
req.extensions_mut().insert(param);
237237

238-
let req = match chain(req, &app, vec![channel_load]).await {
238+
let req = match chain(req, app, vec![channel_load]).await {
239239
Ok(req) => req,
240240
Err(error) => {
241241
return Err(error);
242242
}
243243
};
244244

245-
channel_status(req, &app).await
245+
channel_status(req, app).await
246246
} else if let (Some(caps), &Method::GET) = (CHANNEL_VALIDATOR_MESSAGES.captures(&path), method)
247247
{
248248
let param = RouteParams(vec![caps
@@ -251,7 +251,7 @@ async fn channels_router<A: Adapter>(
251251

252252
req.extensions_mut().insert(param);
253253

254-
let req = match chain(req, &app, vec![channel_load]).await {
254+
let req = match chain(req, app, vec![channel_load]).await {
255255
Ok(req) => req,
256256
Err(error) => {
257257
return Err(error);
@@ -267,11 +267,9 @@ async fn channels_router<A: Adapter>(
267267
};
268268

269269
list_validator_messages(req, &app, &extract_params.0, &extract_params.1).await
270-
} else if let (Some(caps), &Method::GET) =
271-
(CHANNEL_EVENTS_AGGREGATES.captures(path), method)
272-
{
270+
} else if let (Some(caps), &Method::GET) = (CHANNEL_EVENTS_AGGREGATES.captures(&path), method) {
273271
if req.extensions().get::<Session>().is_none() {
274-
return map_response_error(ResponseError::Unauthorized);
272+
return Err(ResponseError::Unauthorized);
275273
}
276274

277275
let param = RouteParams(vec![
@@ -282,14 +280,9 @@ async fn channels_router<A: Adapter>(
282280
]);
283281
req.extensions_mut().insert(param);
284282

285-
let req = match chain(req, &self, vec![channel_load]).await {
286-
Ok(req) => req,
287-
Err(error) => {
288-
return map_response_error(error);
289-
}
290-
};
283+
let req = chain(req, app, vec![channel_load]).await?;
291284

292-
list_channel_event_aggregates(req, &self).await
285+
list_channel_event_aggregates(req, app).await
293286
} else {
294287
Err(ResponseError::NotFound)
295288
}
@@ -299,7 +292,7 @@ async fn channels_router<A: Adapter>(
299292
pub enum ResponseError {
300293
NotFound,
301294
BadRequest(String),
302-
UnAuthorized,
295+
Unauthorized,
303296
}
304297

305298
impl<T> From<T> for ResponseError
@@ -317,7 +310,7 @@ pub fn map_response_error(error: ResponseError) -> Response<Body> {
317310
match error {
318311
ResponseError::NotFound => not_found(),
319312
ResponseError::BadRequest(e) => bad_response(e, StatusCode::BAD_REQUEST),
320-
ResponseError::UnAuthorized => bad_response(
313+
ResponseError::Unauthorized => bad_response(
321314
"invalid authorization".to_string(),
322315
StatusCode::UNAUTHORIZED,
323316
),

sentry/src/routes/analytics.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub async fn publisher_analytics<A: Adapter>(
2020
None => None,
2121
};
2222
let analytics_type = AnalyticsType::Publisher {
23-
session: sess.cloned().ok_or(ResponseError::UnAuthorized)?,
23+
session: sess.cloned().ok_or(ResponseError::Unauthorized)?,
2424
channel,
2525
};
2626

@@ -72,7 +72,7 @@ pub async fn advertiser_analytics<A: Adapter>(
7272
None => None,
7373
};
7474
let analytics_type = AnalyticsType::Advertiser {
75-
session: sess.ok_or(ResponseError::UnAuthorized)?.to_owned(),
75+
session: sess.ok_or(ResponseError::Unauthorized)?.to_owned(),
7676
channel,
7777
};
7878

0 commit comments

Comments
 (0)