Download crates/forge_eventsource/src/error.rs from SaylorTwift/forgecode: direct link, hf CLI and curl.
- Browser
- Download file 1.98 kB
-
https://huggingface.co/SaylorTwift/forgecode/resolve/main/crates/forge_eventsource/src/error.rs
- Command line
-
hf download hf://SaylorTwift/forgecode/crates/forge_eventsource/src/error.rs
-
curl -L -o error.rs https://huggingface.co/SaylorTwift/forgecode/resolve/main/crates/forge_eventsource/src/error.rs
1.98 kB
| use core::fmt; | |
| use std::string::FromUtf8Error; | |
| use forge_eventsource_stream::EventStreamError; | |
| use nom::error::Error as NomError; | |
| use reqwest::RequestBuilder; | |
| use reqwest::header::HeaderValue; | |
| use reqwest::{Error as ReqwestError, Response, StatusCode}; | |
| /// Error raised when a [`RequestBuilder`] cannot be cloned. See | |
| /// [`RequestBuilder::try_clone`] for more information | |
| pub struct CannotCloneRequestError; | |
| impl fmt::Display for CannotCloneRequestError { | |
| fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | |
| f.write_str("expected a cloneable request") | |
| } | |
| } | |
| impl std::error::Error for CannotCloneRequestError {} | |
| /// Error raised by the EventSource stream fetching and parsing | |
| pub enum Error { | |
| /// Source stream is not valid UTF8 | |
| Utf8(FromUtf8Error), | |
| /// Source stream is not a valid EventStream | |
| Parser(NomError<String>), | |
| /// The HTTP Request could not be completed | |
| Transport(ReqwestError), | |
| /// The `Content-Type` returned by the server is invalid | |
| InvalidContentType(HeaderValue, Box<Response>), | |
| /// The status code returned by the server is invalid | |
| InvalidStatusCode(StatusCode, Box<Response>), | |
| /// The `Last-Event-ID` cannot be formed into a Header to be submitted to | |
| /// the server | |
| InvalidLastEventId(String), | |
| /// The stream ended | |
| StreamEnded, | |
| } | |
| impl From<EventStreamError<ReqwestError>> for Error { | |
| fn from(err: EventStreamError<ReqwestError>) -> Self { | |
| match err { | |
| EventStreamError::Utf8(err) => Self::Utf8(err), | |
| EventStreamError::Parser(err) => Self::Parser(err), | |
| EventStreamError::Transport(err) => Self::Transport(err), | |
| } | |
| } | |
| } | |