Skip to content

Commit

Permalink
Present the inner reason of network errors
Browse files Browse the repository at this point in the history
If the CarteroError is nested, extract the inner reason rather than
saying a generic error.
  • Loading branch information
danirod committed Feb 7, 2025
1 parent f8d3202 commit 7b494f4
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
6 changes: 4 additions & 2 deletions data/ui/response_panel.blp
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,13 @@ template $CarteroResponsePanel: Adw.Bin {

child: Adw.StatusPage error_page {
icon-name: "network-error-symbolic";
title: _("Request error");
title: _("Cannot perform request");

child: Gtk.Label error_extra {
label: "PRUEBA";
label: "";
selectable: true;
opacity: 0.75;
wrap: true;
};
};
}
Expand Down
11 changes: 11 additions & 0 deletions src/client/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,17 @@ pub enum RequestError {
IOError(#[from] std::io::Error),
}

impl RequestError {
pub fn inner_error(&self) -> String {
match self {
Self::NetworkError(isahc) => isahc.to_string(),
Self::HttpError(isahc) => isahc.to_string(),
Self::IOError(io) => io.to_string(),
_ => self.to_string(),
}
}
}

#[cfg(test)]
mod tests {
use crate::entities::KeyValueTable;
Expand Down
18 changes: 16 additions & 2 deletions src/widgets/response_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,23 @@ mod imp {

pub(super) fn show_error(&self, error: CarteroError) {
// TODO: Internationalize
let message = error.to_string();
println!("{error:?}");
let message = match &error {
CarteroError::Request(inner) => inner.to_string(),
_ => error.to_string(),
};

match &error {
CarteroError::Request(inner) => {
self.error_extra.set_visible(true);
self.error_extra.set_label(&inner.inner_error());
}
_ => {
self.error_extra.set_visible(false);
}
}

self.error_page.set_description(Some(&message));
self.error_extra.set_visible(false);
self.stack.set_visible_child_name("error");
}
}
Expand Down

0 comments on commit 7b494f4

Please sign in to comment.