Skip to main content

rfham_geo/
error.rs

1//! Error and result types for `rfham-geo`.
2//!
3//! [`GeoError`] is the single error enum used across all modules in this crate.
4//! [`GeoResult<T>`] is a type alias for `std::result::Result<T, GeoError>`.
5
6use lat_long::Error as LatLongError;
7use reqwest::Error as RequestError;
8use reqwest::StatusCode;
9use rfham_core::error::CoreError;
10use serde_json::Error as JsonError;
11use thiserror::Error;
12
13// ------------------------------------------------------------------------------------------------
14// Public Types
15// ------------------------------------------------------------------------------------------------
16
17///
18/// The `Error` type for this crate.
19///
20#[derive(Debug, Error)]
21pub enum GeoError {
22    #[error("I/O error: {0}")]
23    Io(#[from] std::io::Error),
24
25    #[error("An error occured converting latitude/longitude value; error: {0}")]
26    LatLong(#[from] LatLongError),
27
28    #[error("Cannot produce a Maidenhead grid locator for either North/South poles")]
29    NoPolarGrid,
30
31    #[error("An error occured in a Geo-IP provider; error: {0}")]
32    GeoIpProvider(String),
33
34    #[error("An HTTP service returned non-success code ; status-code: {0}")]
35    Http(StatusCode),
36
37    #[error("An error occured calling an HTTP service; status-code: {0}")]
38    Reqwest(#[from] RequestError),
39
40    #[error("Core library error detected; error: {0}")]
41    Core(#[from] CoreError),
42
43    #[error("An error occured serializing/deserializing JSON; error: {0}")]
44    Serialization(#[from] JsonError),
45}
46
47///
48/// A `Result` type that specifically uses this crate's `Error`.
49///
50pub type GeoResult<T> = std::result::Result<T, GeoError>;