Skip to content

Commit c772273

Browse files
authored
Merge pull request #2 from MicroPanda123/add/display-error
feat: add support for thiserror
2 parents 0daf098 + ab3689e commit c772273

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "altcha-lib-rs"
3-
version = "0.1.2"
3+
version = "0.1.3"
44
edition = "2021"
55
authors = ["jmic <jmic@users.noreply.github.com>"]
66
description = "Community implementation of the Altcha library in Rust for your own server application to create and validate challenges and responses."
@@ -25,11 +25,12 @@ sha1 = "0"
2525
hmac = "0"
2626
serde = { version = "1.0", features = ["derive"] }
2727
serde_json = { version = "1.0", optional = true }
28+
thiserror = "2.0.12"
2829

2930
[features]
3031
default = []
3132
json = ["serde_json"]
3233

3334
[dev-dependencies]
3435
actix-web = "4"
35-
base64 = "0.22"
36+
base64 = "0.22"

src/error.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,25 @@
1-
#[derive(Debug)]
1+
#[derive(Debug, thiserror::Error)]
22
pub enum Error {
33
#[cfg(feature = "json")]
4+
#[error("JSON parsing error: {0}")]
45
ParseJson(serde_json::Error),
6+
#[error("Integer parsing error: {0}")]
57
ParseInteger(std::num::ParseIntError),
8+
#[error("Expiration parsing error: {0}")]
69
ParseExpire(String),
10+
#[error("Solution expired: {0}")]
711
VerificationFailedExpired(String),
12+
#[error("Solution does not match the challenge: {0}")]
813
VerificationMismatchChallenge(String),
14+
#[error("Signature in the solution does not match the challenge: {0}")]
915
VerificationMismatchSignature(String),
16+
#[error("Max number reached: {0}")]
1017
SolveChallengeMaxNumberReached(String),
18+
#[error("Wrong challenge input: {0}")]
1119
WrongChallengeInput(String),
20+
#[error("Altcha error: {0}")]
1221
General(String),
22+
#[error("Error in the randomizer: {0}")]
1323
RandError(rand::distr::uniform::Error),
1424
}
1525

0 commit comments

Comments
 (0)