Skip to main content

hs_predict/pubchem/
error.rs

1use thiserror::Error;
2
3/// Errors produced by the PubChem API client.
4#[derive(Debug, Error)]
5pub enum PubChemError {
6    /// PubChem returned no compound matching the given input.
7    #[error("No compound found in PubChem for: '{input}'")]
8    NotFound { input: String },
9
10    /// The `SubstanceIdentifier` has no field usable for a PubChem lookup.
11    ///
12    /// At least one of: CAS number, SMILES, InChIKey, InChI, or IUPAC name
13    /// must be present.
14    #[error("SubstanceIdentifier has no usable field for PubChem lookup (provide CAS, SMILES, InChIKey, InChI, or IUPAC name)")]
15    NoUsableIdentifier,
16
17    /// HTTP-level error (network failure, server error, etc.).
18    #[error("PubChem HTTP error: {0}")]
19    Http(String),
20
21    /// The API response could not be parsed.
22    #[error("Failed to parse PubChem response: {0}")]
23    Parse(String),
24
25    /// PubChem server returned a rate-limit response (HTTP 429).
26    #[error("PubChem rate limit exceeded — retry after a few seconds")]
27    RateLimitExceeded,
28}