@@ -64,8 +64,7 @@ async fn auth_required_middleware<A: Adapter>(
64
64
if req. extensions ( ) . get :: < Session > ( ) . is_some ( ) {
65
65
Ok ( req)
66
66
} else {
67
- Ok ( req)
68
- // Err(ResponseError::BadRequest("auth required".to_string()))
67
+ Err ( ResponseError :: UnAuthorized )
69
68
}
70
69
}
71
70
@@ -274,6 +273,7 @@ async fn channels_router<A: Adapter>(
274
273
pub enum ResponseError {
275
274
NotFound ,
276
275
BadRequest ( String ) ,
276
+ UnAuthorized ,
277
277
}
278
278
279
279
impl < T > From < T > for ResponseError
@@ -290,7 +290,8 @@ where
290
290
pub fn map_response_error ( error : ResponseError ) -> Response < Body > {
291
291
match error {
292
292
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 ) ,
294
295
}
295
296
}
296
297
@@ -301,7 +302,7 @@ pub fn not_found() -> Response<Body> {
301
302
response
302
303
}
303
304
304
- pub fn bad_response ( response_body : String ) -> Response < Body > {
305
+ pub fn bad_response ( response_body : String , status_code : StatusCode ) -> Response < Body > {
305
306
let mut error_response = HashMap :: new ( ) ;
306
307
error_response. insert ( "error" , response_body) ;
307
308
@@ -312,12 +313,12 @@ pub fn bad_response(response_body: String) -> Response<Body> {
312
313
. headers_mut ( )
313
314
. insert ( "Content-type" , "application/json" . parse ( ) . unwrap ( ) ) ;
314
315
315
- let status = response. status_mut ( ) ;
316
- * status = StatusCode :: BAD_REQUEST ;
317
-
316
+ * response. status_mut ( ) = status_code;
317
+
318
318
response
319
319
}
320
320
321
+
321
322
pub fn success_response ( response_body : String ) -> Response < Body > {
322
323
let body = Body :: from ( response_body) ;
323
324
0 commit comments