1use std::fmt;
4
5#[derive(Debug, thiserror::Error)]
7pub enum ViiperError {
8 #[error("transport error: {0}")]
10 Io(#[from] std::io::Error),
11
12 #[error("{0}")]
14 Protocol(#[from] ProblemJson),
15
16 #[error("parse error: {0}")]
18 Parse(#[from] serde_json::Error),
19
20 #[error("unexpected response: {0}")]
22 UnexpectedResponse(String),
23
24 #[cfg(feature = "async")]
26 #[error("operation timed out")]
27 Timeout,
28}
29
30#[derive(Debug, Clone, serde::Deserialize)]
32pub struct ProblemJson {
33 pub status: u16,
34 pub title: String,
35 pub detail: String,
36}
37
38impl fmt::Display for ProblemJson {
39 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
40 write!(f, "{} {}: {}", self.status, self.title, self.detail)
41 }
42}
43
44impl std::error::Error for ProblemJson {}