stytch/
lib.rs

1use serde::{Deserialize, Serialize};
2
3#[derive(thiserror::Error, Debug)]
4#[non_exhaustive]
5pub enum Error {
6    #[error("{0:?}")]
7    Response(ErrorResponse),
8
9    #[error(transparent)]
10    InvalidHeaderValue(#[from] http::header::InvalidHeaderValue),
11
12    #[error(transparent)]
13    InvalidUrl(#[from] url::ParseError),
14
15    #[error("Failed to fetch JWKS")]
16    FetchJwks,
17
18    #[error("{0:?}")]
19    JwkNotFound(String),
20
21    #[error("Unauthorized")]
22    Unauthorized,
23
24    #[error(transparent)]
25    JWTError(#[from] crate::shared::jwt_helpers::JWTError),
26
27    #[error(transparent)]
28    Other(#[from] Box<dyn std::error::Error + Send + Sync>),
29}
30
31pub type Result<T> = std::result::Result<T, Error>;
32
33pub struct Request<Body: Serialize + Send> {
34    pub method: http::Method,
35    pub path: String,
36    pub body: Body,
37}
38
39#[derive(Serialize, Deserialize, Debug)]
40pub struct ErrorResponse {
41    #[serde(with = "http_serde::status_code")]
42    pub status_code: http::StatusCode,
43    pub request_id: String,
44
45    #[serde(alias = "error_type", alias = "error")]
46    pub error_type: String,
47    #[serde(alias = "error_message", alias = "error_description")]
48    pub error_message: String,
49    #[serde(alias = "error_url", alias = "error_uri")]
50    pub error_url: String,
51}
52
53pub mod b2b;
54pub mod client;
55pub mod consumer;
56mod shared;