1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2025-06-21 00:45:18 +00:00

Fix returned error in case of bad login tokens

This commit is contained in:
2020-05-24 18:33:47 +02:00
parent 399900077f
commit 89d5eac02b
2 changed files with 36 additions and 36 deletions

View File

@ -1,16 +1,18 @@
use actix_web::{web, HttpRequest, HttpResponse};
use crate::controllers::routes::RequestResult;
use std::error::Error;
use serde::Serialize;
use crate::data::error::{ResultBoxError, ExecError};
use std::collections::HashMap;
use crate::helpers::{api_helper, account_helper};
use actix_web::http::{HeaderName, HeaderValue};
use std::error::Error;
use std::str::FromStr;
use crate::data::config::conf;
use crate::data::api_client::APIClient;
use actix_web::{HttpRequest, HttpResponse, web};
use actix_web::http::{HeaderName, HeaderValue};
use serde::Serialize;
use crate::api_data::http_error::HttpError;
use crate::controllers::routes::RequestResult;
use crate::data::api_client::APIClient;
use crate::data::config::conf;
use crate::data::error::{ExecError, ResultBoxError};
use crate::data::user::UserID;
use crate::helpers::{account_helper, api_helper};
/// Http request handler
///
@ -217,13 +219,21 @@ impl HttpRequestHandler {
let token = self.post_string("userToken1")?;
// Find user
let user_id = self.ok_or_bad_request(
account_helper::get_user_by_login_token(&token, self.api_client()),
"Please check your login tokens!")?;
match account_helper::get_user_by_login_token(&token, self.api_client()) {
Ok(id) => {
self.curr_user_id = Some(id);
self.curr_user_id = Some(user_id);
Ok(())
Ok(())
}
Err(e) => {
println!("Error marking login tokens as invalid: {}", e);
self.response = Some(
actix_web::HttpResponse::
build(actix_web::http::StatusCode::from_u16(412)?)
.json(HttpError::new(412, "Please check your login tokens!")));
Err(e)
}
}
}
/// Get user ID. This function assess that a user ID is available to continue