MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / from_body

Method from_body

atomic-remote/src/http/identity.rs:57–73  ·  view source on GitHub ↗

Parse a `409` response body; `None` when it is not a usable JSON object. The flat `{"code", "message"}` spelling is expected, and the nested `{"error": {…}}` spelling is accepted so either server shape surfaces its reason.

(body: &str)

Source from the content-addressed store, hash-verified

55 /// nested `{"error": {…}}` spelling is accepted so either server shape
56 /// surfaces its reason.
57 fn from_body(body: &str) -> Option<Self> {
58 let parsed: Value = serde_json::from_str(body).ok()?;
59 let (code, message) = match parsed.get("error") {
60 Some(nested) => (
61 nested.get("code").and_then(|v| v.as_str()),
62 nested.get("message").and_then(|v| v.as_str()),
63 ),
64 None => (
65 parsed.get("code").and_then(|v| v.as_str()),
66 parsed.get("message").and_then(|v| v.as_str()),
67 ),
68 };
69 Some(Self {
70 code: code.map(str::to_owned),
71 message: message.map(str::to_owned),
72 })
73 }
74}
75
76/// What the follow-up read of the remote binding resolved to after a `409`,

Callers

nothing calls this directly

Calls 3

getMethod · 0.65
okMethod · 0.45
as_strMethod · 0.45

Tested by

no test coverage detected