A better Rust ATProto crate
1use jacquard_common::session::SessionStoreError; 2use miette::Diagnostic; 3 4use crate::resolver::ResolverError; 5 6/// Errors emitted by OAuth helpers. 7#[derive(Debug, thiserror::Error, Diagnostic)] 8pub enum OAuthError { 9 /// Invalid or unsupported JWK 10 #[error("invalid JWK: {0}")] 11 #[diagnostic( 12 code(jacquard_oauth::jwk), 13 help("Ensure EC P-256 JWK with base64url x,y,d values") 14 )] 15 Jwk(String), 16 /// Signing error 17 #[error("signing error: {0}")] 18 #[diagnostic( 19 code(jacquard_oauth::signing), 20 help("Check ES256 key material and input payloads") 21 )] 22 Signing(String), 23 /// Serialization error 24 #[error(transparent)] 25 #[diagnostic(code(jacquard_oauth::serde))] 26 Serde(#[from] serde_json::Error), 27 /// URL error 28 #[error(transparent)] 29 #[diagnostic(code(jacquard_oauth::url))] 30 Url(#[from] url::ParseError), 31 /// URL error 32 #[error(transparent)] 33 #[diagnostic(code(jacquard_oauth::url))] 34 UrlEncoding(#[from] serde_html_form::ser::Error), 35 /// PKCE error 36 #[error("pkce error: {0}")] 37 #[diagnostic( 38 code(jacquard_oauth::pkce), 39 help("PKCE must use S256; ensure verifier/challenge generated") 40 )] 41 Pkce(String), 42 #[error("authorize error: {0}")] 43 Authorize(String), 44 #[error(transparent)] 45 Atproto(#[from] crate::atproto::Error), 46 #[error("callback error: {0}")] 47 Callback(String), 48 #[error(transparent)] 49 Storage(#[from] SessionStoreError), 50 #[error(transparent)] 51 Session(#[from] crate::session::Error), 52 #[error(transparent)] 53 Request(#[from] crate::request::Error), 54 #[error(transparent)] 55 Client(#[from] ResolverError), 56} 57 58pub type Result<T> = core::result::Result<T, OAuthError>;