A refusal as the contract's [`pb::ErrorInfo`]: `VIEW_STALE` for a stale view, `CHANGE_REJECTED` otherwise, with the variant in [`REJECTION_REASON`] and its fields beside it so the other side can rebuild it ([`rejection_from_error_info`]).
(rejection: &SubmitRejection)
| 245 | /// [`REJECTION_REASON`] and its fields beside it so the other side can |
| 246 | /// rebuild it ([`rejection_from_error_info`]). |
| 247 | pub fn rejection_error_info(rejection: &SubmitRejection) -> pb::ErrorInfo { |
| 248 | let mut context = HashMap::new(); |
| 249 | let mut put = |k: &str, v: &str| { |
| 250 | context.insert(k.to_string(), v.to_string()); |
| 251 | }; |
| 252 | let (code, reason) = match rejection { |
| 253 | SubmitRejection::HashMismatch { claimed, computed } => { |
| 254 | put("claimed", claimed); |
| 255 | put("computed", computed); |
| 256 | (ErrorCode::ChangeRejected, "hash_mismatch") |
| 257 | } |
| 258 | SubmitRejection::Malformed(why) => { |
| 259 | put("detail", why); |
| 260 | (ErrorCode::ChangeRejected, "malformed") |
| 261 | } |
| 262 | SubmitRejection::StaleView { current } => { |
| 263 | put("current", current); |
| 264 | (ErrorCode::ViewStale, "stale_view") |
| 265 | } |
| 266 | SubmitRejection::ForeignChange(change) => { |
| 267 | put("change", change); |
| 268 | (ErrorCode::ChangeRejected, "foreign_change") |
| 269 | } |
| 270 | SubmitRejection::ForeignNode(node) => { |
| 271 | put("node", &node.to_string()); |
| 272 | (ErrorCode::ChangeRejected, "foreign_node") |
| 273 | } |
| 274 | SubmitRejection::ForbiddenPath(path) => { |
| 275 | put("path", path); |
| 276 | (ErrorCode::ChangeRejected, "forbidden_path") |
| 277 | } |
| 278 | SubmitRejection::AlreadyPresent(change) => { |
| 279 | put("change", change); |
| 280 | (ErrorCode::ChangeRejected, "already_present") |
| 281 | } |
| 282 | }; |
| 283 | put(REJECTION_REASON, reason); |
| 284 | pb::ErrorInfo { |
| 285 | code: code as i32, |
| 286 | message: rejection.to_string(), |
| 287 | context, |
| 288 | request_id: None, |
| 289 | } |
| 290 | } |
| 291 | |
| 292 | /// The [`SubmitRejection`] an [`pb::ErrorInfo`] from |
| 293 | /// [`rejection_error_info`] describes, if it is one. |