subhojit777 / questionnaire-backend

Real-time crowd survey application (Back-end)
http://subhojit777.in/questionnaire-backend/
MIT License
4 stars 2 forks source link

Use oauth to guard POST /answers #10

Closed subhojit777 closed 5 years ago

subhojit777 commented 5 years ago

Next steps:

subhojit777 commented 5 years ago

Blocked because of the error

error[E0308]: match arms have incompatible types --> src/answers.rs:34:34 34 .and_then( code match code { __^ 35 StatusCode::OK => { 36 let answer = answer_form.into_inner(); 37 ... 47 StatusCode::FORBIDDEN => Ok(HttpResponse::Forbidden().into()), ------------------------------------ match arm with an incompatible type 48 _ => Ok(HttpResponse::NotAcceptable().into()), 49 }) _____^ expected struct futures::AndThen, found enum std::result::Result

= note: expected type futures::AndThen<futures::future::FromErr<actix_web::actix::Request<DbExecutor, models::AnswerForm>, _>, std::result::Result<actix_web::HttpResponse, _>, [closure@src/answers.rs:42:39: 45:30]> found type std::result::Result<_, _>

I think this should fix it https://stackoverflow.com/questions/53119182/conditionally-chaining-a-rust-future-based-on-initial-future-result

subhojit777 commented 5 years ago

The above approach will not work, because conditionally it returns AndThen or Result, however, it should return only Return. And I don't think it is possible to do that here. Therefore, I have decided to move the guard check to middleware. I am following https://users.rust-lang.org/t/trouble-with-lifetimes-in-actix-web-middleware/21836 for code.