src/server/formatter.rs: rename format_result to format_data
To avoid confusions with Rust Result type.
This commit is contained in:
parent
21ee7912fa
commit
d55037e471
|
@ -11,7 +11,7 @@ pub struct ErrorMessageExtension(pub String);
|
|||
|
||||
pub struct OutputFormatter {
|
||||
|
||||
pub format_result: fn(data: Value, rpcenv: &RpcEnvironment) -> Response<Body>,
|
||||
pub format_data: fn(data: Value, rpcenv: &RpcEnvironment) -> Response<Body>,
|
||||
|
||||
pub format_error: fn(err: Error) -> Response<Body>,
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ pub fn json_response(result: Value) -> Response<Body> {
|
|||
response
|
||||
}
|
||||
|
||||
fn json_format_result(data: Value, rpcenv: &RpcEnvironment) -> Response<Body> {
|
||||
fn json_format_data(data: Value, rpcenv: &RpcEnvironment) -> Response<Body> {
|
||||
|
||||
let mut result = json!({
|
||||
"data": data
|
||||
|
@ -72,11 +72,11 @@ pub fn json_format_error(err: Error) -> Response<Body> {
|
|||
}
|
||||
|
||||
pub static JSON_FORMATTER: OutputFormatter = OutputFormatter {
|
||||
format_result: json_format_result,
|
||||
format_data: json_format_data,
|
||||
format_error: json_format_error,
|
||||
};
|
||||
|
||||
fn extjs_format_result(data: Value, rpcenv: &RpcEnvironment) -> Response<Body> {
|
||||
fn extjs_format_data(data: Value, rpcenv: &RpcEnvironment) -> Response<Body> {
|
||||
|
||||
let mut result = json!({
|
||||
"data": data,
|
||||
|
@ -116,6 +116,6 @@ fn extjs_format_error(err: Error) -> Response<Body> {
|
|||
}
|
||||
|
||||
pub static EXTJS_FORMATTER: OutputFormatter = OutputFormatter {
|
||||
format_result: extjs_format_result,
|
||||
format_data: extjs_format_data,
|
||||
format_error: extjs_format_error,
|
||||
};
|
||||
|
|
|
@ -240,7 +240,7 @@ pub fn handle_sync_api_request<Env: RpcEnvironment>(
|
|||
.and_then(move |params| {
|
||||
let mut delay = false;
|
||||
let resp = match (info.handler.as_ref().unwrap())(params, info, &mut rpcenv) {
|
||||
Ok(data) => (formatter.format_result)(data, &rpcenv),
|
||||
Ok(data) => (formatter.format_data)(data, &rpcenv),
|
||||
Err(err) => {
|
||||
if let Some(httperr) = err.downcast_ref::<HttpError>() {
|
||||
if httperr.code == StatusCode::UNAUTHORIZED { delay = true; }
|
||||
|
|
Loading…
Reference in New Issue