companies_house_api/streaming/
error.rs

1use reqwest::StatusCode;
2use thiserror::Error;
3
4use super::operation::StreamItem;
5
6#[derive(Debug, Error)]
7pub enum CompaniesHouseStreamingConnectionError {
8    #[error("Connection timeout exceeded")]
9    ConnectionTimeout,
10    #[error("Unknown error connecting to stream endpoint")]
11    UnknownConnection(reqwest::Error),
12    #[error("Not authorised to connect to this stream")]
13    Unauthorized,
14    #[error("Rate limiting")]
15    TooManyRequests,
16    #[error("Timepoint specified is invalid or too old")]
17    BadTimepoint,
18    #[error("Unknown connection response {0}")]
19    UnknownResponse(StatusCode),
20}
21
22#[derive(Debug, Error)]
23pub enum CompaniesHouseStreamingNextError {
24    #[error("Stream chunk timeout exceeded")]
25    ChunkTimeout,
26    #[error("Stream has no more items and a new connection is required")]
27    StreamComplete,
28    #[error("Unable to read from response body")]
29    BadChunk(reqwest::Error),
30    #[error("Unable to read utf8 from response body")]
31    BadItemEncoding(std::str::Utf8Error),
32    #[error("Unable to deserialize next stream item as JSON: {inner}")]
33    BadItemJson {
34        inner: serde_json::Error,
35        text: String,
36    },
37    #[error("Unable to convert JSON to data type: {inner}")]
38    BadItemData {
39        inner: serde_json::Error,
40        value: StreamItem<serde_json::Value>,
41    },
42}