Refactor errors and some other stuff/fixes
This commit is contained in:
parent
8d996888bd
commit
5a7b2de0ea
28 changed files with 507 additions and 341 deletions
emgauwa-core/src/handlers/v1/ws
|
@ -1,11 +1,12 @@
|
|||
use std::time::Instant;
|
||||
|
||||
use actix::Addr;
|
||||
use actix_web::{get, web, HttpRequest, HttpResponse};
|
||||
use actix_web_actors::ws;
|
||||
use emgauwa_lib::types::ConnectedControllersType;
|
||||
use emgauwa_lib::errors::{ApiError, EmgauwaError};
|
||||
use sqlx::{Pool, Sqlite};
|
||||
|
||||
use crate::handlers::errors::ApiError;
|
||||
use crate::app_state::AppServer;
|
||||
use crate::handlers::v1::ws::controllers::ControllerWs;
|
||||
|
||||
pub mod controllers;
|
||||
|
@ -13,20 +14,24 @@ pub mod controllers;
|
|||
#[get("/api/v1/ws/controllers")]
|
||||
pub async fn ws_controllers(
|
||||
pool: web::Data<Pool<Sqlite>>,
|
||||
connected_controllers: web::Data<ConnectedControllersType>,
|
||||
app_server: web::Data<Addr<AppServer>>,
|
||||
req: HttpRequest,
|
||||
stream: web::Payload,
|
||||
) -> Result<HttpResponse, ApiError> {
|
||||
) -> Result<HttpResponse, EmgauwaError> {
|
||||
let resp = ws::start(
|
||||
ControllerWs {
|
||||
pool: pool.get_ref().clone(),
|
||||
controller_uid: None,
|
||||
connected_controllers: connected_controllers.get_ref().clone(),
|
||||
app_server: app_server.get_ref().clone(),
|
||||
hb: Instant::now(),
|
||||
},
|
||||
&req,
|
||||
stream,
|
||||
)
|
||||
.map_err(|_| ApiError::InternalError(String::from("error starting websocket")));
|
||||
.map_err(|_| {
|
||||
EmgauwaError::from(ApiError::InternalError(String::from(
|
||||
"error starting websocket",
|
||||
)))
|
||||
});
|
||||
resp
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue