Got backend using errors.

This commit is contained in:
2025-04-25 14:02:40 -04:00
parent cb9bac9d8a
commit 55ffa538e8
4 changed files with 166 additions and 14 deletions

View File

@ -1,12 +1,12 @@
use axum::{
extract::{Extension, FromRequestParts, State},
http::request::Parts,
http::{request::Parts, StatusCode},
response::IntoResponse,
routing::{get, post},
RequestPartsExt, Router,
};
use clap::Parser;
use morethantext::MoreThanText;
use morethantext::{ActionType, MoreThanText};
use std::convert::Infallible;
use tokio::{spawn, sync::mpsc::channel};
use tower_cookies::{Cookie, CookieManagerLayer, Cookies};
@ -83,10 +83,14 @@ where
async fn mtt_conn(sess_id: SessionID, state: State<MoreThanText>) -> impl IntoResponse {
let (tx, mut rx) = channel(1);
spawn(async move {
tx.send(state.get_document(sess_id.0)).await.unwrap();
tx.send(state.get_document(sess_id.0, ActionType::Get, "root")).await.unwrap();
});
let content = rx.recv().await.unwrap();
content
let reply = rx.recv().await.unwrap();
let status = match reply.get_error() {
Some(_) => StatusCode::NOT_FOUND,
None => StatusCode::OK,
};
(status, reply.get_document())
}
#[cfg(test)]
@ -97,7 +101,7 @@ mod servers {
http::{
header::{COOKIE, SET_COOKIE},
Method,
Request, StatusCode,
Request,
},
};
use tower::ServiceExt;