1use crate::proto::Error;
23use std::{error, fmt, io};
45/// Errors caused by sending a message
6#[derive(Debug)]
7pub enum SendError {
8 Connection(Error),
9 User(UserError),
10}
1112/// Errors caused by users of the library
13#[derive(Debug)]
14pub enum UserError {
15/// The stream ID is no longer accepting frames.
16InactiveStreamId,
1718/// The stream is not currently expecting a frame of this type.
19UnexpectedFrameType,
2021/// The payload size is too big
22PayloadTooBig,
2324/// The application attempted to initiate too many streams to remote.
25Rejected,
2627/// The released capacity is larger than claimed capacity.
28ReleaseCapacityTooBig,
2930/// The stream ID space is overflowed.
31 ///
32 /// A new connection is needed.
33OverflowedStreamId,
3435/// Illegal headers, such as connection-specific headers.
36MalformedHeaders,
3738/// Request submitted with relative URI.
39MissingUriSchemeAndAuthority,
4041/// Calls `SendResponse::poll_reset` after having called `send_response`.
42PollResetAfterSendResponse,
4344/// Calls `PingPong::send_ping` before receiving a pong.
45SendPingWhilePending,
4647/// Tries to update local SETTINGS while ACK has not been received.
48SendSettingsWhilePending,
4950/// Tries to send push promise to peer who has disabled server push
51PeerDisabledServerPush,
52}
5354// ===== impl SendError =====
5556impl error::Error for SendError {}
5758impl fmt::Display for SendError {
59fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
60match *self {
61Self::Connection(ref e) => e.fmt(fmt),
62Self::User(ref e) => e.fmt(fmt),
63 }
64 }
65}
6667impl From<io::Error> for SendError {
68fn from(src: io::Error) -> Self {
69Self::Connection(src.into())
70 }
71}
7273impl From<UserError> for SendError {
74fn from(src: UserError) -> Self {
75 SendError::User(src)
76 }
77}
7879// ===== impl UserError =====
8081impl error::Error for UserError {}
8283impl fmt::Display for UserError {
84fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
85use self::UserError::*;
8687 fmt.write_str(match *self {
88 InactiveStreamId => "inactive stream",
89 UnexpectedFrameType => "unexpected frame type",
90 PayloadTooBig => "payload too big",
91 Rejected => "rejected",
92 ReleaseCapacityTooBig => "release capacity too big",
93 OverflowedStreamId => "stream ID overflowed",
94 MalformedHeaders => "malformed headers",
95 MissingUriSchemeAndAuthority => "request URI missing scheme and authority",
96 PollResetAfterSendResponse => "poll_reset after send_response is illegal",
97 SendPingWhilePending => "send_ping before received previous pong",
98 SendSettingsWhilePending => "sending SETTINGS before received previous ACK",
99 PeerDisabledServerPush => "sending PUSH_PROMISE to peer who disabled server push",
100 })
101 }
102}