pub fn make_error(
req: &Msg,
err_type: MsgType,
error_code: i32,
dyn_error_code: DynErrorCode,
pool: &MbufPool,
) -> MsgExpand description
Build a synthetic error response for req.
The constructed message inherits the request’s id (so the
dispatcher can pair them), sets is_request to false, marks the
response as in-error, stamps the error codes, and attaches the
rendered wire-format error string in one or more mbufs taken
from pool so the client driver actually has bytes to write
back.
The wire formats produced are:
- Redis (RESP):
RspRedisError:-Dynomite: <message>\r\nRspRedisErrorErr:-ERR <message>\r\nRspRedisErrorOom:-OOM <message>\r\nRspRedisErrorBusy:-BUSY <message>\r\nRspRedisErrorNoauth:-NOAUTH <message>\r\nRspRedisErrorLoading:-LOADING <message>\r\nRspRedisErrorBusykey:-BUSYKEY <message>\r\nRspRedisErrorMisconf:-MISCONF <message>\r\nRspRedisErrorNoscript:-NOSCRIPT <message>\r\nRspRedisErrorReadonly:-READONLY <message>\r\nRspRedisErrorWrongtype:-WRONGTYPE <message>\r\nRspRedisErrorExecabort:-EXECABORT <message>\r\nRspRedisErrorMasterdown:-MASTERDOWN <message>\r\nRspRedisErrorNoreplicas:-NOREPLICAS <message>\r\n
- Memcache (text):
RspMcServerError:SERVER_ERROR <message>\r\nRspMcClientError:CLIENT_ERROR <message>\r\nRspMcError:ERROR\r\n
<message> is DynErrorCode::message.
§Examples
use dynomite::io::mbuf::MbufPool;
use dynomite::msg::{response, DynErrorCode, Msg, MsgType};
let req = Msg::new(7, MsgType::ReqRedisGet, true);
let pool = MbufPool::default();
let rsp = response::make_error(
&req,
MsgType::RspRedisError,
13,
DynErrorCode::PeerHostDown,
&pool,
);
assert_eq!(rsp.parent_id(), 7);
assert!(rsp.flags().is_error);
let bytes: Vec<u8> = rsp.mbufs().iter().flat_map(|b| b.readable().to_vec()).collect();
assert_eq!(bytes, b"-Dynomite: Peer Node is down\r\n".to_vec());