Skip to content

Commit

Permalink
Properly handle erros
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitrylavrenov committed Jul 19, 2024
1 parent 4d4ff3c commit 475f021
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 20 deletions.
5 changes: 1 addition & 4 deletions crates/bioauth-flow-rpc/src/errors/authenticate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,7 @@ where
Error::Sign(err) => rpc_error_response::simple(api_error_code::SIGN, err.to_string()),
Error::Robonode(
ref err @ robonode_client::Error::Call(
robonode_client::AuthenticateError::InvalidLivenessData(Some(
ref scan_result_blob,
))
| robonode_client::AuthenticateError::PersonNotFound(Some(ref scan_result_blob))
robonode_client::AuthenticateError::PersonNotFound(Some(ref scan_result_blob))
| robonode_client::AuthenticateError::FaceScanRejected(Some(
ref scan_result_blob,
))
Expand Down
5 changes: 1 addition & 4 deletions crates/bioauth-flow-rpc/src/errors/enroll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,7 @@ impl From<Error> for jsonrpsee::core::Error {
}
Error::Robonode(
ref err @ robonode_client::Error::Call(
robonode_client::EnrollError::InvalidPublicKey(Some(ref scan_result_blob))
| robonode_client::EnrollError::InvalidLivenessData(Some(ref scan_result_blob))
| robonode_client::EnrollError::FaceScanRejected(Some(ref scan_result_blob))
| robonode_client::EnrollError::PublicKeyAlreadyUsed(Some(ref scan_result_blob))
robonode_client::EnrollError::FaceScanRejected(Some(ref scan_result_blob))
| robonode_client::EnrollError::PersonAlreadyEnrolled(Some(ref scan_result_blob))
| robonode_client::EnrollError::LogicInternal(Some(ref scan_result_blob)),
),
Expand Down
6 changes: 3 additions & 3 deletions crates/robonode-client/src/authenticate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub struct AuthenticateResponse {
pub enum AuthenticateError {
/// The provided liveness data was invalid.
#[error("invalid liveness data")]
InvalidLivenessData(Option<ScanResultBlob>),
InvalidLivenessData,
/// The person was not found, it is likely because they haven't enrolled first.
#[error("person not found")]
PersonNotFound(Option<ScanResultBlob>),
Expand Down Expand Up @@ -86,7 +86,7 @@ impl AuthenticateError {
Err(body) => return Self::Unknown(body),
};
match error_code.as_str() {
"AUTHENTICATE_INVALID_LIVENESS_DATA" => Self::InvalidLivenessData(scan_result_blob),
"AUTHENTICATE_INVALID_LIVENESS_DATA" => Self::InvalidLivenessData,
"AUTHENTICATE_PERSON_NOT_FOUND" => Self::PersonNotFound(scan_result_blob),
"AUTHENTICATE_FACE_SCAN_REJECTED" => Self::FaceScanRejected(scan_result_blob),
"AUTHENTICATE_SIGNATURE_INVALID" => Self::SignatureInvalid(scan_result_blob),
Expand Down Expand Up @@ -176,7 +176,7 @@ mod tests {
(
StatusCode::BAD_REQUEST,
"AUTHENTICATE_INVALID_LIVENESS_DATA",
AuthenticateError::InvalidLivenessData(Some("scan result blob".to_owned())),
AuthenticateError::InvalidLivenessData,
),
(
StatusCode::NOT_FOUND,
Expand Down
18 changes: 9 additions & 9 deletions crates/robonode-client/src/enroll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,16 @@ pub struct EnrollResponse {
pub enum EnrollError {
/// The public key is invalid.
#[error("invalid public key")]
InvalidPublicKey(Option<ScanResultBlob>),
InvalidPublicKey,
/// The liveness data is invalid.
#[error("invalid liveness data")]
InvalidLivenessData(Option<ScanResultBlob>),
InvalidLivenessData,
/// The face scan was rejeted.
#[error("face scan rejected")]
FaceScanRejected(Option<ScanResultBlob>),
/// The public key is already used.
#[error("public key already used")]
PublicKeyAlreadyUsed(Option<ScanResultBlob>),
PublicKeyAlreadyUsed,
/// The person is already enrolled.
#[error("person already enrolled")]
PersonAlreadyEnrolled(Option<ScanResultBlob>),
Expand All @@ -87,10 +87,10 @@ impl EnrollError {
Err(body) => return Self::Unknown(body),
};
match error_code.as_str() {
"ENROLL_INVALID_PUBLIC_KEY" => Self::InvalidPublicKey(scan_result_blob),
"ENROLL_INVALID_LIVENESS_DATA" => Self::InvalidLivenessData(scan_result_blob),
"ENROLL_INVALID_PUBLIC_KEY" => Self::InvalidPublicKey,
"ENROLL_INVALID_LIVENESS_DATA" => Self::InvalidLivenessData,
"ENROLL_FACE_SCAN_REJECTED" => Self::FaceScanRejected(scan_result_blob),
"ENROLL_PUBLIC_KEY_ALREADY_USED" => Self::PublicKeyAlreadyUsed(scan_result_blob),
"ENROLL_PUBLIC_KEY_ALREADY_USED" => Self::PublicKeyAlreadyUsed,
"ENROLL_PERSON_ALREADY_ENROLLED" => Self::PersonAlreadyEnrolled(scan_result_blob),
"LOGIC_INTERNAL_ERROR" => Self::LogicInternal(scan_result_blob),
_ => Self::UnknownCode(error_code),
Expand Down Expand Up @@ -162,12 +162,12 @@ mod tests {
(
StatusCode::BAD_REQUEST,
"ENROLL_INVALID_PUBLIC_KEY",
EnrollError::InvalidPublicKey(Some("scan result blob".to_owned())),
EnrollError::InvalidPublicKey,
),
(
StatusCode::BAD_REQUEST,
"ENROLL_INVALID_LIVENESS_DATA",
EnrollError::InvalidLivenessData(Some("scan result blob".to_owned())),
EnrollError::InvalidLivenessData,
),
(
StatusCode::FORBIDDEN,
Expand All @@ -177,7 +177,7 @@ mod tests {
(
StatusCode::CONFLICT,
"ENROLL_PUBLIC_KEY_ALREADY_USED",
EnrollError::PublicKeyAlreadyUsed(Some("scan result blob".to_owned())),
EnrollError::PublicKeyAlreadyUsed,
),
(
StatusCode::CONFLICT,
Expand Down

0 comments on commit 475f021

Please sign in to comment.