rama_http_core/h2/codec/
error.rs1use crate::h2::{frame::StreamIdOverflow, proto::Error};
2
3use std::{error, fmt, io};
4
5#[derive(Debug)]
7pub enum SendError {
8 Connection(Error),
9 User(UserError),
10}
11
12#[derive(Debug)]
14pub enum UserError {
15 InactiveStreamId,
17
18 UnexpectedFrameType,
20
21 PayloadTooBig,
23
24 Rejected,
26
27 ReleaseCapacityTooBig,
29
30 OverflowedStreamId,
34
35 MalformedHeaders,
37
38 MissingUriSchemeAndAuthority,
40
41 PollResetAfterSendResponse,
43
44 SendPingWhilePending,
46
47 SendSettingsWhilePending,
49
50 PeerDisabledServerPush,
52}
53
54impl error::Error for SendError {}
57
58impl fmt::Display for SendError {
59 fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
60 match *self {
61 Self::Connection(ref e) => e.fmt(fmt),
62 Self::User(ref e) => e.fmt(fmt),
63 }
64 }
65}
66
67impl From<io::Error> for SendError {
68 fn from(src: io::Error) -> Self {
69 Self::Connection(src.into())
70 }
71}
72
73impl From<UserError> for SendError {
74 fn from(src: UserError) -> Self {
75 SendError::User(src)
76 }
77}
78
79impl From<StreamIdOverflow> for SendError {
80 fn from(_: StreamIdOverflow) -> Self {
81 UserError::OverflowedStreamId.into()
82 }
83}
84
85impl error::Error for UserError {}
88
89impl fmt::Display for UserError {
90 fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
91 fmt.write_str(match *self {
92 UserError::InactiveStreamId => "inactive stream",
93 UserError::UnexpectedFrameType => "unexpected frame type",
94 UserError::PayloadTooBig => "payload too big",
95 UserError::Rejected => "rejected",
96 UserError::ReleaseCapacityTooBig => "release capacity too big",
97 UserError::OverflowedStreamId => "stream ID overflowed",
98 UserError::MalformedHeaders => "malformed headers",
99 UserError::MissingUriSchemeAndAuthority => "request URI missing scheme and authority",
100 UserError::PollResetAfterSendResponse => "poll_reset after send_response is illegal",
101 UserError::SendPingWhilePending => "send_ping before received previous pong",
102 UserError::SendSettingsWhilePending => "sending SETTINGS before received previous ACK",
103 UserError::PeerDisabledServerPush => {
104 "sending PUSH_PROMISE to peer who disabled server push"
105 }
106 })
107 }
108}