http-server: fix error types

This commit is contained in:
dr-frmr 2024-12-23 01:49:23 -05:00
parent d23d454ad1
commit 35e0334703
No known key found for this signature in database
2 changed files with 20 additions and 56 deletions

View File

@ -104,9 +104,7 @@ async fn send_push(
id, id,
source, source,
send_to_loop, send_to_loop,
Err(HttpServerError::WebSocketPushError { Err(HttpServerError::WsPingPongTooLong),
error: "Ping and Pong messages must be 125 bytes or less".to_string(),
}),
) )
.await; .await;
return true; return true;
@ -130,9 +128,7 @@ async fn send_push(
id, id,
source, source,
send_to_loop, send_to_loop,
Err(HttpServerError::WebSocketPushError { Err(HttpServerError::WsChannelNotFound),
error: "WebSocket channel not owned by this process".to_string(),
}),
) )
.await; .await;
return true; return true;
@ -144,9 +140,7 @@ async fn send_push(
id, id,
source.clone(), source.clone(),
send_to_loop, send_to_loop,
Err(HttpServerError::WebSocketPushError { Err(HttpServerError::WsChannelNotFound),
error: "WebSocket channel closed".to_string(),
}),
) )
.await; .await;
return true; return true;
@ -157,9 +151,7 @@ async fn send_push(
id, id,
source.clone(), source.clone(),
send_to_loop, send_to_loop,
Err(HttpServerError::WebSocketPushError { Err(HttpServerError::WsChannelNotFound),
error: "WebSocket channel not found".to_string(),
}),
) )
.await; .await;
return true; return true;
@ -1180,9 +1172,7 @@ async fn handle_app_message(
km.id, km.id,
km.source, km.source,
&send_to_loop, &send_to_loop,
Err(HttpServerError::BadRequest { Err(HttpServerError::MalformedRequest),
req: String::from_utf8_lossy(body).to_string(),
}),
) )
.await; .await;
return; return;
@ -1200,12 +1190,7 @@ async fn handle_app_message(
km.id, km.id,
km.source, km.source,
&send_to_loop, &send_to_loop,
Err(HttpServerError::PathBindError { Err(HttpServerError::InvalidSourceProcess),
error: format!(
"invalid source process (not Kimap safe): {}",
source
),
}),
) )
.await; .await;
return; return;
@ -1271,12 +1256,7 @@ async fn handle_app_message(
km.id, km.id,
km.source, km.source,
&send_to_loop, &send_to_loop,
Err(HttpServerError::PathBindError { Err(HttpServerError::InvalidSourceProcess),
error: format!(
"invalid source process (not Kimap safe): {}",
source
),
}),
) )
.await; .await;
return; return;
@ -1356,12 +1336,7 @@ async fn handle_app_message(
km.id, km.id,
km.source, km.source,
&send_to_loop, &send_to_loop,
Err(HttpServerError::PathBindError { Err(HttpServerError::InvalidSourceProcess),
error: format!(
"invalid source process (not Kimap safe): {}",
source
),
}),
) )
.await; .await;
return; return;
@ -1385,12 +1360,7 @@ async fn handle_app_message(
km.id, km.id,
km.source, km.source,
&send_to_loop, &send_to_loop,
Err(HttpServerError::PathBindError { Err(HttpServerError::InvalidSourceProcess),
error: format!(
"invalid source process (not Kimap safe): {}",
source
),
}),
) )
.await; .await;
return; return;
@ -1427,9 +1397,7 @@ async fn handle_app_message(
km.id, km.id,
km.source.clone(), km.source.clone(),
&send_to_loop, &send_to_loop,
Err(HttpServerError::WebSocketPushError { Err(HttpServerError::MalformedRequest),
error: "WebSocketOpen is not a valid request".to_string(),
}),
) )
.await; .await;
} }
@ -1475,10 +1443,7 @@ async fn handle_app_message(
km.id, km.id,
km.source, km.source,
&send_to_loop, &send_to_loop,
Err(HttpServerError::WebSocketPushError { Err(HttpServerError::MalformedRequest),
error: "Use WebSocketExtPushOutgoing, not WebSocketExtPushData"
.to_string(),
}),
) )
.await; .await;
return; return;
@ -1490,10 +1455,7 @@ async fn handle_app_message(
km.id, km.id,
km.source, km.source,
&send_to_loop, &send_to_loop,
Err(HttpServerError::WebSocketPushError { Err(HttpServerError::WsChannelNotFound),
error: "WebSocket channel not owned by this process"
.to_string(),
}),
) )
.await; .await;
return; return;

View File

@ -169,14 +169,16 @@ pub enum WsMessageType {
/// Part of the Response type issued by `http-server:distro:sys` /// Part of the Response type issued by `http-server:distro:sys`
#[derive(Error, Debug, Serialize, Deserialize)] #[derive(Error, Debug, Serialize, Deserialize)]
pub enum HttpServerError { pub enum HttpServerError {
#[error("request could not be parsed to HttpServerAction: {req}.")] #[error("request could not be deserialized to valid HttpServerRequest")]
BadRequest { req: String }, MalformedRequest,
#[error("action expected blob")] #[error("action expected blob")]
NoBlob, NoBlob,
#[error("path binding error: {error}")] #[error("path binding error: invalid source process")]
PathBindError { error: String }, InvalidSourceProcess,
#[error("WebSocket error: {error}")] #[error("WebSocket error: ping/pong message too long")]
WebSocketPushError { error: String }, WsPingPongTooLong,
#[error("WebSocket error: channel not found")]
WsChannelNotFound,
} }
/// Structure sent from client websocket to this server upon opening a new connection. /// Structure sent from client websocket to this server upon opening a new connection.