feat: error handling
This commit is contained in:
parent
3c4f3b7533
commit
17c802bab8
6 changed files with 145 additions and 59 deletions
|
@ -2,10 +2,7 @@ use std::{any::type_name_of_val, error::Error};
|
|||
|
||||
use http_body_util::{Either, Full};
|
||||
use hyper::{
|
||||
Request, Response,
|
||||
body::{Body, Bytes, Incoming},
|
||||
server::conn::http1,
|
||||
service::{HttpService, Service},
|
||||
body::{Body, Bytes, Incoming}, server::conn::http1, service::{HttpService, Service}, Request, Response, StatusCode
|
||||
};
|
||||
use hyper_util::rt::TokioIo;
|
||||
use log::{error, info};
|
||||
|
@ -28,6 +25,22 @@ pub trait TcpIntercept {
|
|||
fn stream(&mut self, stream: &TcpStream);
|
||||
}
|
||||
|
||||
pub async fn default_response() -> GeneralResponse {
|
||||
Response::builder()
|
||||
.status(404)
|
||||
.body(GeneralBody::Right(Full::from(Bytes::from(
|
||||
"That route doesn't exist.",
|
||||
))))
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
pub async fn custom_resp(e: StatusCode, m: &'static str) -> GeneralResponse {
|
||||
Response::builder()
|
||||
.status(e)
|
||||
.body(GeneralBody::Right(Full::from(Bytes::from(m))))
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
impl<S> Server<S>
|
||||
where
|
||||
S: TcpIntercept,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue