Simple Nextcloud Forms https://forms.42l.fr
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

62 lines
2.3 KiB

use crate::templates::TplError;
use actix_web::dev::HttpResponseBuilder;
use actix_web::{error, http::header, http::StatusCode, HttpResponse};
use askama::Template;
use std::fmt;
pub fn crash(lang: String, error_msg: &'static str) -> TrainCrash {
TrainCrash { lang, error_msg }
}
#[derive(Debug)]
pub struct TrainCrash {
pub error_msg: &'static str,
pub lang: String,
}
// gonna avoid using failure crate
// by implementing display
impl fmt::Display for TrainCrash {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{:?}", self.error_msg)
}
}
impl error::ResponseError for TrainCrash {
fn error_response(&self) -> HttpResponse {
eprintln!("Error reached: {}", self.error_msg);
HttpResponseBuilder::new(self.status_code())
.set_header(header::CONTENT_TYPE, "text/html; charset=utf-8")
.body(
TplError {
lang: &self.lang,
error_msg: self.error_msg,
}
.render()
.expect("error_tplrender (TplError). Empty page sent to client."),
)
}
fn status_code(&self) -> StatusCode {
match self.error_msg {
"error_forward_req" => StatusCode::BAD_GATEWAY,
"error_forward_resp" => StatusCode::BAD_GATEWAY,
"error_login_get" => StatusCode::BAD_GATEWAY,
"error_login_get_body" => StatusCode::BAD_GATEWAY,
"error_login_post" => StatusCode::BAD_GATEWAY,
"error_login_redir" => StatusCode::BAD_GATEWAY,
"error_createaccount_post" => StatusCode::BAD_GATEWAY,
"error_createaccount_post_body" => StatusCode::BAD_GATEWAY,
"error_createaccount_status" => StatusCode::BAD_GATEWAY,
"error_createaccount_ncstatus" => StatusCode::BAD_GATEWAY,
"error_forwardlogin_notfound" => StatusCode::NOT_FOUND,
"error_forwardregister_tokenparse" => StatusCode::BAD_REQUEST,
"error_login_cookiepair" => StatusCode::BAD_GATEWAY,
"error_login_regex" => StatusCode::BAD_GATEWAY,
"error_login_setcookie" => StatusCode::BAD_REQUEST,
"error_createaccount" => StatusCode::BAD_GATEWAY,
"error_dirtyhacker" => StatusCode::UNAUTHORIZED,
_ => StatusCode::INTERNAL_SERVER_ERROR,
}
}
}