Skip to content

Commit 306037d

Browse files
committed
fix(rivetkit-core): preserve user error metadata
1 parent a04f44b commit 306037d

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

rivetkit-rust/packages/rivetkit-core/src/error.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use serde_json::Value as JsonValue;
44

55
pub fn public_error_status_code(group: &str, code: &str) -> Option<u16> {
66
match (group, code) {
7+
("user", _) => Some(400),
78
("auth", "forbidden") => Some(403),
89
("actor", "action_not_found") => Some(404),
910
("actor", "action_timed_out") => Some(408),

rivetkit-rust/packages/rivetkit-core/tests/modules/action_dispatch_error.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,31 @@ fn preserves_public_error_message_for_client_boundary() {
2929
assert_eq!(error.client_message(), "action `missing` was not found");
3030
}
3131

32+
#[test]
33+
fn preserves_user_error_metadata_for_client_boundary() {
34+
let metadata = serde_json::json!({
35+
"error": {
36+
"_tag": "CounterOverflowError",
37+
"limit": 20,
38+
},
39+
});
40+
let error = ActionDispatchError::from_anyhow(anyhow::Error::new(RivetError {
41+
kind: RivetErrorKind::Dynamic {
42+
group: "user".to_owned(),
43+
code: "Increment".to_owned(),
44+
default_message: "count 25 would exceed limit 20".to_owned(),
45+
},
46+
meta: serde_json::value::to_raw_value(&metadata).ok(),
47+
message: None,
48+
actor: None,
49+
}));
50+
51+
assert_eq!(error.group, "user");
52+
assert_eq!(error.code, "Increment");
53+
assert_eq!(error.client_message(), "count 25 would exceed limit 20");
54+
assert_eq!(error.client_metadata(), Some(&metadata));
55+
}
56+
3257
#[test]
3358
fn masks_private_structured_message_at_client_boundary() {
3459
static TEST_ERROR: RivetErrorSchema = RivetErrorSchema {

0 commit comments

Comments
 (0)