Skip to content

Commit 812c97d

Browse files
committed
fix: add unauthorized error repsonse
1 parent ba36277 commit 812c97d

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

sentry/src/db/analytics.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::db::DbPool;
22
use crate::Session;
33
use bb8::RunError;
44
use chrono::Utc;
5-
use primitives::analytics::{AnalyticsQuery, AnalyticsResponse};
5+
use primitives::analytics::{AnalyticsQuery, AnalyticsResponse, ANALYTICS_QUERY_LIMIT};
66

77
pub async fn get_analytics(
88
query: AnalyticsQuery,
@@ -12,7 +12,7 @@ pub async fn get_analytics(
1212
is_advertiser: bool,
1313
filter_publisher: bool,
1414
) -> Result<Vec<AnalyticsResponse>, RunError<bb8_postgres::tokio_postgres::Error>> {
15-
let applied_limit = query.limit.min(200);
15+
let applied_limit = query.limit.min(ANALYTICS_QUERY_LIMIT);
1616
let (interval, period) = get_time_frame(&query.timeframe);
1717
let time_limit = Utc::now().timestamp() - period;
1818

sentry/src/lib.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,7 @@ async fn auth_required_middleware<A: Adapter>(
6464
if req.extensions().get::<Session>().is_some() {
6565
Ok(req)
6666
} else {
67-
Ok(req)
68-
// Err(ResponseError::BadRequest("auth required".to_string()))
67+
Err(ResponseError::UnAuthorized)
6968
}
7069
}
7170

@@ -274,6 +273,7 @@ async fn channels_router<A: Adapter>(
274273
pub enum ResponseError {
275274
NotFound,
276275
BadRequest(String),
276+
UnAuthorized,
277277
}
278278

279279
impl<T> From<T> for ResponseError
@@ -290,7 +290,8 @@ where
290290
pub fn map_response_error(error: ResponseError) -> Response<Body> {
291291
match error {
292292
ResponseError::NotFound => not_found(),
293-
ResponseError::BadRequest(e) => bad_response(e),
293+
ResponseError::BadRequest(e) => bad_response(e, StatusCode::BAD_REQUEST),
294+
ResponseError::UnAuthorized => bad_response("invalid authorization".to_string(), StatusCode::UNAUTHORIZED),
294295
}
295296
}
296297

@@ -301,7 +302,7 @@ pub fn not_found() -> Response<Body> {
301302
response
302303
}
303304

304-
pub fn bad_response(response_body: String) -> Response<Body> {
305+
pub fn bad_response(response_body: String, status_code: StatusCode) -> Response<Body> {
305306
let mut error_response = HashMap::new();
306307
error_response.insert("error", response_body);
307308

@@ -312,12 +313,12 @@ pub fn bad_response(response_body: String) -> Response<Body> {
312313
.headers_mut()
313314
.insert("Content-type", "application/json".parse().unwrap());
314315

315-
let status = response.status_mut();
316-
*status = StatusCode::BAD_REQUEST;
317-
316+
*response.status_mut() = status_code;
317+
318318
response
319319
}
320320

321+
321322
pub fn success_response(response_body: String) -> Response<Body> {
322323
let body = Body::from(response_body);
323324

0 commit comments

Comments
 (0)