Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

feat(transport): distinguish channel-message 404 from unmatched-route 404

Steven Enamakele6c1109ccb9f
diff --git a/crates/openhuman-tinyhumans/src/transport/error.rs b/crates/openhuman-tinyhumans/src/transport/error.rs
index 5ae7edcad2..d7187d233e 100644
--- a/crates/openhuman-tinyhumans/src/transport/error.rs
+++ b/crates/openhuman-tinyhumans/src/transport/error.rs
@@ -4,10 +4,39 @@
//! the SDK directly.
use openhuman_core::backend::transport::BackendTransportError;
+use reqwest::Method;
+use tinyhumans_sdk::classify::channel_message_path;
use tinyhumans_sdk::Error as SdkError;
-/// Map the SDK's error onto the core-owned transport error.
-pub fn map_sdk_error(error: SdkError) -> BackendTransportError {
+/// Map the SDK's error for `method path` onto the core-owned transport error.
+///
+/// A `404` on a channel-message route becomes a typed variant here, because
+/// only this backend's wire behaviour says what it means: a handler's JSON
+/// 404 is a message that no longer exists, while an unmatched-route 404
+/// (Express `finalhandler` HTML) on `PATCH` is the edit route the backend never
+/// implemented (#5230) — the message is still there. The core recovers from
+/// the two differently and never inspects the body itself.
+pub fn map_sdk_error(error: SdkError, method: &Method, path: &str) -> BackendTransportError {
+ if let SdkError::Status { status: 404, .. } = &error {
+ if let Some((provider, message_id)) = channel_message_path(path) {
+ let (provider, message_id) = (provider.to_owned(), message_id.to_owned());
+ if *method == Method::PATCH && error.is_unmatched_route_404() {
+ log::debug!(
+ "[tinyhumans-transport] {method} {path}: 404 with no matching route; \
+ channel edit route missing"
+ );
+ return BackendTransportError::ChannelMessageRouteMissing {
+ provider,
+ message_id,
+ };
+ }
+ log::debug!("[tinyhumans-transport] {method} {path}: channel message not found");
+ return BackendTransportError::ChannelMessageNotFound {
+ provider,
+ message_id,
+ };
+ }
+ }
match error {
SdkError::Url(e) => BackendTransportError::Url(e.to_string()),
SdkError::Http(e) => BackendTransportError::Http(e),
diff --git a/crates/openhuman-tinyhumans/src/transport/mod.rs b/crates/openhuman-tinyhumans/src/transport/mod.rs
index 9946f898df..30a3a77f80 100644
--- a/crates/openhuman-tinyhumans/src/transport/mod.rs
+++ b/crates/openhuman-tinyhumans/src/transport/mod.rs
@@ -10,6 +10,7 @@ use openhuman_core::backend::{
BackendRequest, BackendTransport, BackendTransportError, BaseUrlPurpose, TransportProfile,
};
use openhuman_core::security::credentials::session_support::BackendCredential;
+use reqwest::Method;
use serde_json::Value;
use tinyhumans_sdk::TinyHumansClient;
@@ -93,7 +94,7 @@ impl BackendTransport for SdkBackendTransport {
req.unwrap_envelope,
)
.await
- .map_err(map_sdk_error)
+ .map_err(|error| map_sdk_error(error, &req.method, req.path))
}
async fn send_multipart(
@@ -110,7 +111,7 @@ impl BackendTransport for SdkBackendTransport {
sdk.raw()
.post_multipart(req.path, form)
.await
- .map_err(map_sdk_error)
+ .map_err(|error| map_sdk_error(error, &Method::POST, req.path))
}
fn http_client(&self, profile: TransportProfile) -> reqwest::Client {