hacker_rs/
errors.rs

1//! Various errors and their conversions for Hacker News API interactions.
2
3use thiserror::Error;
4
5use crate::items::HackerNewsItemType;
6
7/// A generic result type mapping downstream errors to their library equivalents.
8pub type HackerNewsResult<T> = Result<T, HackerNewsClientError>;
9
10/// Exported types for handling internal errors with the client.
11#[derive(Debug, Error)]
12pub enum HackerNewsClientError {
13    /// Reports errors that occur when making HTTP requests to Hacker News.
14    #[error("{0}")]
15    RequestError(#[from] reqwest::Error),
16    /// Represents an error that occurred while attempting to parse the response into an invalid Hacker News item subtype.
17    #[error("The requested item was not a valid {0} type.")]
18    InvalidTypeMapping(HackerNewsItemType),
19}