mirror of
https://github.com/YGGverse/ggemini.git
synced 2026-04-01 17:45:35 +00:00
handle errors
This commit is contained in:
parent
16ed3efef0
commit
f4cb0c3bcc
2 changed files with 13 additions and 4 deletions
|
|
@ -47,15 +47,20 @@ impl Connection {
|
||||||
|
|
||||||
/// Close owned [SocketConnection](https://docs.gtk.org/gio/class.SocketConnection.html)
|
/// Close owned [SocketConnection](https://docs.gtk.org/gio/class.SocketConnection.html)
|
||||||
/// and [TlsClientConnection](https://docs.gtk.org/gio/iface.TlsClientConnection.html) if active
|
/// and [TlsClientConnection](https://docs.gtk.org/gio/iface.TlsClientConnection.html) if active
|
||||||
pub fn close(&self, cancellable: Option<&Cancellable>) {
|
pub fn close(&self, cancellable: Option<&Cancellable>) -> Result<(), Error> {
|
||||||
if let Some(ref tls_client_connection) = self.tls_client_connection {
|
if let Some(ref tls_client_connection) = self.tls_client_connection {
|
||||||
if !tls_client_connection.is_closed() {
|
if !tls_client_connection.is_closed() {
|
||||||
tls_client_connection.close(cancellable);
|
if let Err(reason) = tls_client_connection.close(cancellable) {
|
||||||
|
return Err(Error::TlsClientConnection(reason));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !self.socket_connection.is_closed() {
|
if !self.socket_connection.is_closed() {
|
||||||
self.socket_connection.close(cancellable);
|
if let Err(reason) = self.socket_connection.close(cancellable) {
|
||||||
|
return Err(Error::SocketConnection(reason));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Getters
|
// Getters
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ use std::fmt::{Display, Formatter, Result};
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
SocketConnectionClosed,
|
SocketConnectionClosed,
|
||||||
|
SocketConnection(glib::Error),
|
||||||
TlsClientConnection(glib::Error),
|
TlsClientConnection(glib::Error),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -10,8 +11,11 @@ impl Display for Error {
|
||||||
fn fmt(&self, f: &mut Formatter) -> Result {
|
fn fmt(&self, f: &mut Formatter) -> Result {
|
||||||
match self {
|
match self {
|
||||||
Self::SocketConnectionClosed => write!(f, "Socket connection closed"),
|
Self::SocketConnectionClosed => write!(f, "Socket connection closed"),
|
||||||
|
Self::SocketConnection(reason) => {
|
||||||
|
write!(f, "Socket connection error: {reason}")
|
||||||
|
}
|
||||||
Self::TlsClientConnection(reason) => {
|
Self::TlsClientConnection(reason) => {
|
||||||
write!(f, "Could not create TLS connection: {reason}")
|
write!(f, "TLS client connection error: {reason}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue