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>,
)
| 50 | /// 403 responses into [`TeamsError::PermissionDenied`]. All other remote errors |
| 51 | /// are wrapped as [`TeamsError::Remote`]. |
| 52 | pub(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)] |
| 81 | mod tests { |