diff --git a/h3/src/error2/error.rs b/h3/src/error2/error.rs index 5f7fbdd1..fb8e2f90 100644 --- a/h3/src/error2/error.rs +++ b/h3/src/error2/error.rs @@ -59,6 +59,54 @@ pub enum StreamError { ConnectionError(ConnectionError), } +/// This enum represents a stream error +#[derive(Debug, Clone)] +#[non_exhaustive] +pub enum ServerStreamError { + /// The error occurred on the stream + #[non_exhaustive] + StreamError { + /// The error code + code: NewCode, + /// The error reason + reason: &'static str, + }, + /// The error occurred on the connection + #[non_exhaustive] + ConnectionError(ConnectionError), + #[non_exhaustive] + /// The received header block is too big + /// The Request has been answered with a 431 Request Header Fields Too Large + HeaderTooBig { actual_size: u64, max_size: u64 }, +} + +impl std::fmt::Display for ServerStreamError { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + ServerStreamError::StreamError { code, reason } => { + write!(f, "Stream error: {:?} - {}", code, reason) + } + ServerStreamError::ConnectionError(err) => write!(f, "Connection error: {}", err), + ServerStreamError::HeaderTooBig { actual_size, max_size } => write!( + f, + "Header too big: actual size: {}, max size: {}", + actual_size, max_size + ), + } + } +} + +impl std::error::Error for ServerStreamError {} + +impl From for ServerStreamError { + fn from(err: StreamError) -> Self { + match err { + StreamError::StreamError { code, reason } => ServerStreamError::StreamError { code, reason }, + StreamError::ConnectionError(err) => ServerStreamError::ConnectionError(err), + } + } +} + impl std::fmt::Display for ConnectionError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { diff --git a/h3/src/error2/internal_error.rs b/h3/src/error2/internal_error.rs index cdd3c014..2f68d49b 100644 --- a/h3/src/error2/internal_error.rs +++ b/h3/src/error2/internal_error.rs @@ -15,8 +15,10 @@ pub enum ErrorScope { /// to represent errors, which have not yet affected the connection or stream state /// /// This error type is generated from the error types of h3s submodules or by the modules itself. +/// +/// This error type is used in functions which handle a http3 request stream #[derive(Debug, Clone, Hash)] -pub struct InternalError { +pub struct InternalRequestStreamError { /// The error scope scope: ErrorScope, /// The error code @@ -24,3 +26,18 @@ pub struct InternalError { /// The error message message: &'static str, } + + +/// This error type represents an internal error type, which is used +/// to represent errors, which have not yet affected the connection state +/// +/// This error type is generated from the error types of h3s submodules or by the modules itself. +/// +/// This error type is used in functions which handle a http3 connection state +#[derive(Debug, Clone, Hash)] +pub struct InternalConnectionError { + /// The error code + code: Code, + /// The error message + message: &'static str, +} \ No newline at end of file diff --git a/h3/src/error2/traits.rs b/h3/src/error2/traits.rs index 3f7c257a..83a6fabe 100644 --- a/h3/src/error2/traits.rs +++ b/h3/src/error2/traits.rs @@ -1,23 +1,32 @@ //! Defines error traits -use crate::config::Config; +use crate::{config::Config, shared_state::ConnectionState2}; -use super::{internal_error::InternalError, ConnectionError}; +use super::{codes::NewCode, internal_error::InternalRequestStreamError, ConnectionError}; /// This trait is implemented for all types which can close the connection -pub(crate) trait CloseConnection { +pub(crate) trait CloseConnection: ConnectionState2 { /// Close the connection - fn handle_error(&mut self, internal_error: InternalError) -> ConnectionError { + fn handle_connection_error( + &mut self, + internal_error: InternalRequestStreamError, + ) -> ConnectionError { + + //self.maybe_conn_error(error) todo!() } + + fn close_connection>(code: &NewCode, reason: T) -> (); } -pub(crate) trait CloseStream { - fn handle_error(&mut self, internal_error: InternalError, config: &Config) -> ConnectionError { +pub(crate) trait CloseStream: CloseConnection { + fn handle_stream_error( + &mut self, + internal_error: InternalRequestStreamError, + config: &Config, + ) -> ConnectionError { todo!() } fn close_stream() -> (); - - fn close_connection() -> (); }