Skip to main content

signer_auth/
errors.rs

1use std::string::FromUtf8Error;
2
3use chrono::Utc;
4
5#[derive(Debug, thiserror::Error)]
6pub enum JWTDecodeError {
7    #[error("解码 base64url 字符串失败: {0}")]
8    Base64urlDecodeError(#[from] base64::DecodeError),
9
10    #[error("转换 UTF-8 字符串失败: {0}")]
11    FromUtf8Error(#[from] FromUtf8Error),
12
13    #[error("反序列化 JSON 字符串失败: {0}")]
14    DeserializeError(#[from] serde_json::Error),
15
16    #[error("签名校验失败: {0}")]
17    VerifyError(#[from] JWTVerifyError),
18}
19
20#[derive(Debug, thiserror::Error)]
21pub enum JWTEncodeError {
22    #[error("序列化 JSON 字符串失败: {0}")]
23    SerializeError(#[from] serde_json::Error),
24
25    #[error("签名生成失败")]
26    SignError,
27}
28
29#[derive(Debug, thiserror::Error)]
30pub enum JWTVerifyError {
31    #[error("Token 生效时间不合法, 有效时间: {expect:?}, 当前时间: {current:?}")]
32    NotBeforeError {
33        expect: chrono::DateTime<Utc>,
34        current: chrono::DateTime<Utc>,
35    },
36    #[error("Token 过期时间不合法, 过期时间: {expect:?}, 当前时间: {current:?}")]
37    ExpiredError {
38        expect: chrono::DateTime<Utc>,
39        current: chrono::DateTime<Utc>,
40    },
41    #[error("Token 签名校验失败: {reason}")]
42    SignatureError { reason: String },
43}