1use std::fmt::Display;
2
3use reqwest::{StatusCode, header::HeaderValue};
4
5#[derive(Debug)]
6pub enum EventError {
7 IoError(std::io::Error),
8}
9
10impl Display for EventError {
11 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
12 match self {
13 EventError::IoError(error) => {
14 write!(f, "failed to process event due to I/O error: {error}")
15 }
16 }
17 }
18}
19
20#[derive(Debug, PartialEq, Eq)]
21pub enum EventSourceError {
22 BadStatus(StatusCode),
23 BadContentType(Option<HeaderValue>),
24}
25
26impl Display for EventSourceError {
27 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
28 match self {
29 EventSourceError::BadStatus(status_code) => {
30 write!(f, "expecting status code `200`, found: {status_code}")
31 }
32 EventSourceError::BadContentType(None) => {
33 write!(
34 f,
35 "expecting \"text/event-stream\" content type, found none"
36 )
37 }
38 EventSourceError::BadContentType(Some(header_value)) => {
39 let content_type = header_value.to_str();
40 match content_type {
41 Ok(content_type) => {
42 write!(
43 f,
44 "expecting \"text/event-stream\", found: \"{content_type}\"",
45 )
46 }
47 Err(_) => {
48 write!(f, "expecting \"text/event-stream\", found invalid value")
49 }
50 }
51 }
52 }
53 }
54}