Skip to main content

ollama_rest/
errors.rs

1//! Error module
2
3use std::fmt::Display;
4
5use reqwest::StatusCode;
6
7#[derive(Debug)]
8pub enum Error {
9    ClientCreation(reqwest::Error),
10    EmptyResponse,
11    ErrorStatus(StatusCode),
12    Event,
13    NoCallback,
14    NotExists,
15    StreamingOff,
16    UrlParsing(url::ParseError),
17    JsonDecoding(serde_json::Error),
18}
19
20impl Display for Error {
21    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
22        write!(f, "{self}")
23    }
24}
25
26impl std::error::Error for Error {}
27
28impl From<reqwest::Error> for Error {
29    fn from(value: reqwest::Error) -> Self {
30        Self::ClientCreation(value)
31    }
32}
33
34impl From<url::ParseError> for Error {
35    fn from(value: url::ParseError) -> Self {
36        Self::UrlParsing(value)
37    }
38}
39
40impl From<serde_json::Error> for Error {
41    fn from(value: serde_json::Error) -> Self {
42        Self::JsonDecoding(value)
43    }
44}