Skip to main content

just_common/
error.rs

1//! Shared transport error types.
2
3use std::string::FromUtf8Error;
4use thiserror::Error;
5
6use reqwest::StatusCode;
7
8/// Errors produced by the shared HTTP/SSE transport layer.
9#[derive(Debug, Error)]
10pub enum TransportError {
11    #[error("invalid configuration: {0}")]
12    InvalidConfig(&'static str),
13
14    #[error("failed to build http client: {0}")]
15    BuildClient(#[source] reqwest::Error),
16
17    #[error("request failed: {0}")]
18    Transport(#[source] reqwest::Error),
19
20    #[error("api returned {status}")]
21    HttpStatus { status: StatusCode, body: String },
22
23    #[error("failed to serialize request body: {0}")]
24    Serialize(#[source] serde_json::Error),
25
26    #[error("failed to deserialize response body: {source}")]
27    Deserialize {
28        #[source]
29        source: serde_json::Error,
30        body: String,
31    },
32
33    #[error("failed to decode streamed response as UTF-8: {0}")]
34    Utf8(#[source] FromUtf8Error),
35
36    #[error("invalid response: {0}")]
37    InvalidResponse(String),
38}