propagate better error from server.check_running()
This commit is contained in:
parent
c516a8df3e
commit
b2a565b0b4
2 changed files with 6 additions and 2 deletions
|
@ -106,6 +106,7 @@ pub(super) fn io_error_code(kind: std::io::ErrorKind) -> StatusCode {
|
||||||
| ErrorKind::TimedOut => StatusCode::GATEWAY_TIMEOUT,
|
| ErrorKind::TimedOut => StatusCode::GATEWAY_TIMEOUT,
|
||||||
| ErrorKind::FileTooLarge => StatusCode::PAYLOAD_TOO_LARGE,
|
| ErrorKind::FileTooLarge => StatusCode::PAYLOAD_TOO_LARGE,
|
||||||
| ErrorKind::StorageFull => StatusCode::INSUFFICIENT_STORAGE,
|
| ErrorKind::StorageFull => StatusCode::INSUFFICIENT_STORAGE,
|
||||||
|
| ErrorKind::Interrupted => StatusCode::SERVICE_UNAVAILABLE,
|
||||||
| _ => StatusCode::INTERNAL_SERVER_ERROR,
|
| _ => StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ use std::{
|
||||||
use ruma::OwnedServerName;
|
use ruma::OwnedServerName;
|
||||||
use tokio::{runtime, sync::broadcast};
|
use tokio::{runtime, sync::broadcast};
|
||||||
|
|
||||||
use crate::{config, config::Config, err, log::Log, metrics::Metrics, Err, Result};
|
use crate::{config, config::Config, log::Log, metrics::Metrics, Err, Result};
|
||||||
|
|
||||||
/// Server runtime state; public portion
|
/// Server runtime state; public portion
|
||||||
pub struct Server {
|
pub struct Server {
|
||||||
|
@ -127,9 +127,12 @@ impl Server {
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn check_running(&self) -> Result {
|
pub fn check_running(&self) -> Result {
|
||||||
|
use std::{io, io::ErrorKind::Interrupted};
|
||||||
|
|
||||||
self.running()
|
self.running()
|
||||||
.then_some(())
|
.then_some(())
|
||||||
.ok_or_else(|| err!(debug_warn!("Server is shutting down.")))
|
.ok_or_else(|| io::Error::new(Interrupted, "Server shutting down"))
|
||||||
|
.map_err(Into::into)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue