| 1 |
use crate::proto::Error; |
| 2 |
|
| 3 |
use std::{error, fmt, io}; |
| 4 |
|
| 5 |
/// Errors caused by sending a message |
| 6 |
#[derive(Debug)] |
| 7 |
pub enum SendError { |
| 8 |
Connection(Error), |
| 9 |
User(UserError), |
| 10 |
} |
| 11 |
|
| 12 |
/// Errors caused by users of the library |
| 13 |
#[derive(Debug)] |
| 14 |
pub enum UserError { |
| 15 |
/// The stream ID is no longer accepting frames. |
| 16 |
InactiveStreamId, |
| 17 |
|
| 18 |
/// The stream is not currently expecting a frame of this type. |
| 19 |
UnexpectedFrameType, |
| 20 |
|
| 21 |
/// The payload size is too big |
| 22 |
PayloadTooBig, |
| 23 |
|
| 24 |
/// The application attempted to initiate too many streams to remote. |
| 25 |
Rejected, |
| 26 |
|
| 27 |
/// The released capacity is larger than claimed capacity. |
| 28 |
ReleaseCapacityTooBig, |
| 29 |
|
| 30 |
/// The stream ID space is overflowed. |
| 31 |
/// |
| 32 |
/// A new connection is needed. |
| 33 |
OverflowedStreamId, |
| 34 |
|
| 35 |
/// Illegal headers, such as connection-specific headers. |
| 36 |
MalformedHeaders, |
| 37 |
|
| 38 |
/// Request submitted with relative URI. |
| 39 |
MissingUriSchemeAndAuthority, |
| 40 |
|
| 41 |
/// Calls `SendResponse::poll_reset` after having called `send_response`. |
| 42 |
PollResetAfterSendResponse, |
| 43 |
|
| 44 |
/// Calls `PingPong::send_ping` before receiving a pong. |
| 45 |
SendPingWhilePending, |
| 46 |
|
| 47 |
/// Tries to update local SETTINGS while ACK has not been received. |
| 48 |
SendSettingsWhilePending, |
| 49 |
|
| 50 |
/// Tries to send push promise to peer who has disabled server push |
| 51 |
PeerDisabledServerPush, |
| 52 |
} |
| 53 |
|
| 54 |
// ===== impl SendError ===== |
| 55 |
|
| 56 |
impl error::Error for SendError {} |
| 57 |
|
| 58 |
impl 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 |
|
| 67 |
impl From<io::Error> for SendError { |
| 68 |
fn from(src: io::Error) -> Self { |
| 69 |
Self::Connection(src.into()) |
| 70 |
} |
| 71 |
} |
| 72 |
|
| 73 |
impl From<UserError> for SendError { |
| 74 |
fn from(src: UserError) -> Self { |
| 75 |
SendError::User(src) |
| 76 |
} |
| 77 |
} |
| 78 |
|
| 79 |
// ===== impl UserError ===== |
| 80 |
|
| 81 |
impl error::Error for UserError {} |
| 82 |
|
| 83 |
impl fmt::Display for UserError { |
| 84 |
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { |
| 85 |
use self::UserError::*; |
| 86 |
|
| 87 |
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 |
} |