improvement: log bad database errors automatically

This commit is contained in:
timokoesters 2020-06-11 10:03:08 +02:00
parent 2368a90584
commit 56d4742201
No known key found for this signature in database
GPG key ID: 24DA7517711A2BA4
13 changed files with 278 additions and 208 deletions

View file

@ -1,5 +1,6 @@
use crate::RumaResponse;
use http::StatusCode;
use log::error;
use rocket::{
response::{self, Responder},
Request,
@ -27,6 +28,7 @@ pub enum Error {
#[error("{0}")]
BadConfig(&'static str),
#[error("{0}")]
/// Don't create this directly. Use Error::bad_database instead.
BadDatabase(&'static str),
#[error("uiaa")]
Uiaa(UiaaInfo),
@ -37,6 +39,13 @@ pub enum Error {
Conflict(&'static str), // This is only needed for when a room alias already exists
}
impl Error {
pub fn bad_database(message: &'static str) -> Self {
error!("BadDatabase: {}", message);
Self::BadDatabase(message)
}
}
#[rocket::async_trait]
impl<'r> Responder<'r> for Error {
async fn respond_to(self, r: &'r Request<'_>) -> response::Result<'r> {