Skip to content

Commit 1f9e238

Browse files
committed
instance config fetching rework
1 parent 612762c commit 1f9e238

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

src/error.rs

+14-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
use crate::proto::CoreError;
21
use axum::{
32
http::StatusCode,
43
response::{IntoResponse, Response},
54
Json,
65
};
76
use serde_json::json;
8-
use tonic::metadata::errors::InvalidMetadataValue;
9-
use tonic::{Code, Status};
7+
use tonic::{metadata::errors::InvalidMetadataValue, Code, Status};
8+
9+
use crate::proto::CoreError;
1010

1111
#[derive(thiserror::Error, Debug)]
1212
pub enum ApiError {
@@ -24,6 +24,8 @@ pub enum ApiError {
2424
InvalidResponseType,
2525
#[error("Permission denied: {0}")]
2626
PermissionDenied(String),
27+
#[error("Enterprise not enabled")]
28+
EnterpriseNotEnabled,
2729
}
2830

2931
impl IntoResponse for ApiError {
@@ -33,6 +35,10 @@ impl IntoResponse for ApiError {
3335
Self::Unauthorized(msg) => (StatusCode::UNAUTHORIZED, msg),
3436
Self::BadRequest(msg) => (StatusCode::BAD_REQUEST, msg),
3537
Self::PermissionDenied(msg) => (StatusCode::FORBIDDEN, msg),
38+
Self::EnterpriseNotEnabled => (
39+
StatusCode::PAYMENT_REQUIRED,
40+
"Enterprise features are not enabled".to_string(),
41+
),
3642
_ => (
3743
StatusCode::INTERNAL_SERVER_ERROR,
3844
"Internal server error".to_string(),
@@ -55,6 +61,11 @@ impl From<CoreError> for ApiError {
5561
Code::Unauthenticated => ApiError::Unauthorized(status.message().to_string()),
5662
Code::InvalidArgument => ApiError::BadRequest(status.message().to_string()),
5763
Code::PermissionDenied => ApiError::PermissionDenied(status.message().to_string()),
64+
Code::FailedPrecondition => match status.message().to_lowercase().as_str() {
65+
// TODO: find a better way than matching on the error message
66+
"no valid license" => ApiError::EnterpriseNotEnabled,
67+
_ => ApiError::Unexpected(status.to_string()),
68+
},
5869
_ => ApiError::Unexpected(status.to_string()),
5970
}
6071
}

src/handlers/mod.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
use crate::{error::ApiError, proto::core_response::Payload};
1+
use std::time::Duration;
2+
23
use axum::{extract::FromRequestParts, http::request::Parts};
34
use axum_client_ip::{InsecureClientIp, LeftmostXForwardedFor};
45
use axum_extra::{headers::UserAgent, TypedHeader};
5-
use std::time::Duration;
66
use tokio::{sync::oneshot::Receiver, time::timeout};
77

88
use super::proto::DeviceInfo;
9+
use crate::{error::ApiError, proto::core_response::Payload};
910

1011
pub(crate) mod desktop_client_mfa;
1112
pub(crate) mod enrollment;

0 commit comments

Comments
 (0)