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

Function map_remote_error

atomic-teams/src/error.rs:52–78  ·  view source on GitHub ↗

Inspect a [`atomic_remote::RemoteError`] and convert HTTP 404 responses into a context-specific [`TeamsError`] using the provided constructor, and HTTP 403 responses into [`TeamsError::PermissionDenied`]. All other remote errors are wrapped as [`TeamsError::Remote`].

(
    err: atomic_remote::RemoteError,
    not_found_msg: impl Into<String>,
)

Source from the content-addressed store, hash-verified

50/// 403 responses into [`TeamsError::PermissionDenied`]. All other remote errors
51/// are wrapped as [`TeamsError::Remote`].
52pub(crate) fn map_remote_error(
53 err: atomic_remote::RemoteError,
54 not_found_msg: impl Into<String>,
55) -> TeamsError {
56 match &err {
57 atomic_remote::RemoteError::HttpError { status, .. } if *status == 404 => {
58 let msg = not_found_msg.into();
59 // Heuristic: pick the most specific "not found" variant based on
60 // whether the message mentions team or member.
61 let lower = msg.to_lowercase();
62 if lower.contains("team") {
63 TeamsError::TeamNotFound(msg)
64 } else if lower.contains("member") || lower.contains("identity") {
65 TeamsError::MemberNotFound(msg)
66 } else {
67 TeamsError::OrgNotFound(msg)
68 }
69 }
70 atomic_remote::RemoteError::HttpError { status, message } if *status == 403 => {
71 TeamsError::PermissionDenied(message.clone())
72 }
73 atomic_remote::RemoteError::HttpError { status, message } if *status == 409 => {
74 TeamsError::AlreadyExists(message.clone())
75 }
76 _ => TeamsError::Remote(err),
77 }
78}
79
80#[cfg(test)]
81mod tests {

Callers 15

list_membersFunction · 0.85
add_memberFunction · 0.85
get_memberFunction · 0.85
update_member_roleFunction · 0.85
remove_memberFunction · 0.85
list_team_membersFunction · 0.85
add_team_memberFunction · 0.85
update_team_member_roleFunction · 0.85
remove_team_memberFunction · 0.85
list_domainsFunction · 0.85
claim_domainFunction · 0.85
verify_domainFunction · 0.85

Calls 3

RemoteClass · 0.85
containsMethod · 0.45
cloneMethod · 0.45