Skip to content

Commit 8ead2cb

Browse files
authored
fix(arroyo-api): propagate auth errors instead of panicking (ArroyoSystems#1066)
Four handlers in udfs.rs and connection_profiles.rs called `authenticate(...).await.unwrap()`, which panics when auth fails. Replace `.unwrap()` with `?` so the error propagates as a proper `ErrorResp`.
1 parent 15982c4 commit 8ead2cb

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

crates/arroyo-api/src/connection_profiles.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ pub async fn test_connection_profile(
6262
bearer_auth: BearerAuth,
6363
WithRejection(Json(req), _): WithRejection<Json<ConnectionProfilePost>, ApiError>,
6464
) -> Result<Json<TestSourceMessage>, ErrorResp> {
65-
let _auth_data = authenticate(&state.database, bearer_auth).await.unwrap();
65+
let _auth_data = authenticate(&state.database, bearer_auth).await?;
6666

6767
let connector = connector_for_type(&req.connector)
6868
.ok_or_else(|| bad_request("Unknown connector type".to_string()))?;

crates/arroyo-api/src/udfs.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ pub async fn create_udf(
6262
bearer_auth: BearerAuth,
6363
WithRejection(Json(req), _): WithRejection<Json<UdfPost>, ApiError>,
6464
) -> Result<Json<GlobalUdf>, ErrorResp> {
65-
let auth_data = authenticate(&state.database, bearer_auth).await.unwrap();
65+
let auth_data = authenticate(&state.database, bearer_auth).await?;
6666

6767
// let transaction = client.transaction().await.map_err(log_and_map)?;
6868
// transaction
@@ -129,7 +129,7 @@ pub async fn get_udfs(
129129
State(state): State<AppState>,
130130
bearer_auth: BearerAuth,
131131
) -> Result<Json<GlobalUdfCollection>, ErrorResp> {
132-
let auth_data = authenticate(&state.database, bearer_auth).await.unwrap();
132+
let auth_data = authenticate(&state.database, bearer_auth).await?;
133133

134134
let udfs =
135135
api_queries::fetch_get_udfs(&state.database.client().await?, &auth_data.organization_id)
@@ -157,7 +157,7 @@ pub async fn delete_udf(
157157
bearer_auth: BearerAuth,
158158
Path(udf_pub_id): Path<String>,
159159
) -> Result<(), ErrorResp> {
160-
let auth_data = authenticate(&state.database, bearer_auth).await.unwrap();
160+
let auth_data = authenticate(&state.database, bearer_auth).await?;
161161

162162
let count = api_queries::execute_delete_udf(
163163
&state.database.client().await?,

0 commit comments

Comments
 (0)