Skip to content

Commit

Permalink
chore(1-3244): add error
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasheartman committed Jan 14, 2025
1 parent 6689b5b commit 9e6c5f8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
8 changes: 5 additions & 3 deletions server/src/client_api.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::cli::EdgeMode;
use crate::cli::{EdgeArgs, EdgeMode};
use crate::error::EdgeError;
use crate::feature_cache::FeatureCache;
use crate::filters::{
Expand Down Expand Up @@ -58,7 +58,9 @@ pub async fn stream_features(

broadcaster.connect(validated_token, query).await
}
_ => Err(EdgeError::FeatureStreamNotEnabled),
_ => Err(EdgeError::Forbidden(
"This endpoint is only enabled in streaming mode".into(),
)),
}
}

Expand Down Expand Up @@ -308,7 +310,7 @@ mod tests {

use crate::auth::token_validator::TokenValidator;
use crate::cli::{OfflineArgs, TokenHeader};
use crate::http::unleash_client::{UnleashClient, ClientMetaInformation};
use crate::http::unleash_client::{ClientMetaInformation, UnleashClient};
use crate::middleware;
use crate::tests::{features_from_disk, upstream_server};
use actix_http::{Request, StatusCode};
Expand Down
3 changes: 3 additions & 0 deletions server/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ pub enum EdgeError {
EdgeTokenError,
EdgeTokenParseError,
FeatureNotFound(String),
Forbidden(String),
FrontendExpectedToBeHydrated(String),
FrontendNotYetHydrated(FrontendHydrationMissing),
HealthCheckError(String),
Expand Down Expand Up @@ -212,6 +213,7 @@ impl Display for EdgeError {
}
EdgeError::InvalidTokenWithStrictBehavior => write!(f, "Edge is running with strict behavior and the token is not subsumed by any registered tokens"),
EdgeError::SseError(message) => write!(f, "{}", message),
EdgeError::Forbidden(reason) => write!(f, "{}", reason),
}
}
}
Expand Down Expand Up @@ -253,6 +255,7 @@ impl ResponseError for EdgeError {
EdgeError::NotReady => StatusCode::SERVICE_UNAVAILABLE,
EdgeError::InvalidTokenWithStrictBehavior => StatusCode::FORBIDDEN,
EdgeError::SseError(_) => StatusCode::INTERNAL_SERVER_ERROR,
EdgeError::Forbidden(_) => StatusCode::FORBIDDEN,
}
}

Expand Down

0 comments on commit 9e6c5f8

Please sign in to comment.