Skip to content

Commit cffb046

Browse files
committed
refactor(error): return ribosome errors to caller
1 parent 9326ab8 commit cffb046

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

src/error.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ use crate::app_selection::AppSelectionError;
44
use axum::http::StatusCode;
55
use axum::response::IntoResponse;
66
use axum::Json;
7+
use holochain_client::ConductorApiError;
8+
use holochain_conductor_api::ExternalApiWireError;
79
use serde::{Deserialize, Serialize};
810

911
/// Core HTTP Gateway error type
@@ -72,6 +74,9 @@ impl HcHttpGatewayError {
7274
HcHttpGatewayError::AppSelectionError(AppSelectionError::MultipleMatching) => {
7375
(StatusCode::INTERNAL_SERVER_ERROR, self.to_string())
7476
}
77+
HcHttpGatewayError::HolochainError(ConductorApiError::ExternalApiWireError(
78+
ExternalApiWireError::RibosomeError(e),
79+
)) => (StatusCode::INTERNAL_SERVER_ERROR, e),
7580
_ => (
7681
StatusCode::INTERNAL_SERVER_ERROR,
7782
"Something went wrong".to_string(),

src/routes/zome_call/tests/responses.rs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use crate::config::{AllowedFns, Configuration};
33
use crate::test::data::new_test_app_info;
44
use crate::test::router::TestRouter;
55
use crate::{MockAdminCall, MockAppCall};
6+
use holochain::holochain_wasmer_host::prelude::WasmErrorInner;
67
use holochain_client::{ConductorApiError, ExternIO};
78
use holochain_conductor_api::ExternalApiWireError;
89
use holochain_types::prelude::DnaHash;
@@ -54,6 +55,32 @@ async fn happy_zome_call() {
5455
assert_eq!(body, r#""return_value""#);
5556
}
5657

58+
#[tokio::test]
59+
async fn ribosome_errors_are_returned() {
60+
let mut app_call = MockAppCall::new();
61+
app_call
62+
.expect_handle_zome_call()
63+
.returning(|_, _, _, _, _| {
64+
Box::pin(async move {
65+
// A bit contrived this error, but close enough to reality.
66+
Err(crate::HcHttpGatewayError::HolochainError(
67+
ConductorApiError::ExternalApiWireError(ExternalApiWireError::RibosomeError(
68+
format!(
69+
"{:?}",
70+
WasmErrorInner::Guest("could not find record xyz".to_string())
71+
),
72+
)),
73+
))
74+
})
75+
});
76+
let router = create_test_router(app_call);
77+
let (status_code, body) = router
78+
.request(&format!("/{DNA_HASH}/{APP_ID}/coordinator/fn_name"))
79+
.await;
80+
assert_eq!(status_code, StatusCode::INTERNAL_SERVER_ERROR);
81+
assert_eq!(body, r#"{"error":"Guest(\"could not find record xyz\")"}"#);
82+
}
83+
5784
#[tokio::test]
5885
async fn app_not_found() {
5986
let mut app_call = MockAppCall::new();
@@ -97,7 +124,7 @@ async fn cell_not_found() {
97124
}
98125

99126
#[tokio::test]
100-
async fn external_api_wire_error() {
127+
async fn other_external_api_wire_error() {
101128
let mut app_call = MockAppCall::new();
102129
app_call
103130
.expect_handle_zome_call()

0 commit comments

Comments
 (0)