macro_rules! error {
($event:expr, $request_id:expr, $error:expr) => { ... };
($event:expr, $request_id:expr, $error:expr, args: $args:expr, kwargs: $kwargs:expr) => { ... };
($event:expr, $request_id:expr, $error:expr, args: $args:expr) => { ... };
($event:expr, $request_id:expr, $error:expr, kwargs: $kwargs:expr) => { ... };
($event:expr, $request_id:expr, $error:expr, $details:expr) => { ... };
($event:expr, $request_id:expr, $error:expr, $details:expr, args: $args:expr) => { ... };
($event:expr, $request_id:expr, $error:expr, $details:expr, kwargs: $kwargs:expr) => { ... };
($event:expr, $request_id:expr, $error:expr, $details:expr, $args:expr, $kwargs:expr) => { ... };
}
Expand description
§Error Macro
This macro is used for constructing wamp errors with default empty or custom details, args, and kwargs.
§Examples
use wamp_core::messages::{WampErrorEvent, WampError};
use wamp_core::error;
use serde_json::{json, Value};
// Create an error with default values
let error = error!(WampErrorEvent::Call, 1, "wamp.error.unknown_realm");
// Which is the same as creating this
let error2 = WampError {
event: WampErrorEvent::Call,
request_id: 1,
details: json!({}),
error: "wamp.error.unknown_realm".to_string(),
args: Value::Null,
kwargs: Value::Null
};
assert_eq!(error, error2);
// Some other ways to use the macro
// Create error with custom details
let _ = error!(WampErrorEvent::Call, 1, "wamp.error.unknown", json!({ "key": "value" }));
// create error with empty default details and custom args or kwargs
let _ = error!(WampErrorEvent::Call, 1, "wamp.error.unknown", args: json!([ 1, 2, 3 ]));
let _ = error!(WampErrorEvent::Call, 1, "wamp.error.unknown", kwargs: json!({ "key": "value" }));
// create error with empty default details and custom args and kwargs
let _ = error!(WampErrorEvent::Call, 1, "wamp.error.unknown", args: json!([ 1, 2, 3 ]), kwargs: json!({ "key": "value" }));
// note that when you use all values, you do not need keyword arguments for args and kwargs
let _ = error!(WampErrorEvent::Call, 1, "wamp.error.unknown", json!({}), json!([1, 2, 3]), json!({ "key": "value" }));