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