Handle translation errors
This commit is contained in:
parent
67ee20d0bb
commit
33a7a6803a
|
@ -1,3 +1,4 @@
|
||||||
|
use crate::i18n::I18nError;
|
||||||
use crate::views;
|
use crate::views;
|
||||||
|
|
||||||
use rocket::response::Redirect;
|
use rocket::response::Redirect;
|
||||||
|
@ -6,6 +7,7 @@ use rocket_contrib::templates::Template;
|
||||||
#[derive(Debug, rocket::response::Responder)]
|
#[derive(Debug, rocket::response::Responder)]
|
||||||
#[response(content_type = "text/html")]
|
#[response(content_type = "text/html")]
|
||||||
pub enum CommonResponse {
|
pub enum CommonResponse {
|
||||||
|
TranslationError(Redirect),
|
||||||
AlreadySignedIn(Redirect),
|
AlreadySignedIn(Redirect),
|
||||||
InvalidAuthenticityToken(Redirect),
|
InvalidAuthenticityToken(Redirect),
|
||||||
NotSignedIn(Redirect),
|
NotSignedIn(Redirect),
|
||||||
|
@ -17,6 +19,12 @@ pub enum CommonResponse {
|
||||||
UnknownError(Template),
|
UnknownError(Template),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<I18nError> for CommonResponse {
|
||||||
|
fn from(_: I18nError) -> Self {
|
||||||
|
Self::TranslationError(Redirect::to("/"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl From<rocket_csrf::VerificationFailure> for CommonResponse {
|
impl From<rocket_csrf::VerificationFailure> for CommonResponse {
|
||||||
fn from(_: rocket_csrf::VerificationFailure) -> Self {
|
fn from(_: rocket_csrf::VerificationFailure) -> Self {
|
||||||
Self::InvalidAuthenticityToken(Redirect::to("/"))
|
Self::InvalidAuthenticityToken(Redirect::to("/"))
|
||||||
|
|
|
@ -14,11 +14,11 @@ pub fn index(
|
||||||
csrf_token: CsrfToken,
|
csrf_token: CsrfToken,
|
||||||
current_user: states::MaybeCurrentUser,
|
current_user: states::MaybeCurrentUser,
|
||||||
) -> Result<Template, CommonResponse> {
|
) -> Result<Template, CommonResponse> {
|
||||||
let l10n = i18n.l10n("en").unwrap();
|
let l10n = i18n.l10n("en")?;
|
||||||
|
|
||||||
let page_context = views::home::Index {
|
let page_context = views::home::Index {
|
||||||
i18n_fedihub: l10n.translate("fedihub").unwrap(),
|
i18n_fedihub: l10n.translate("fedihub")?,
|
||||||
i18n_federated_services_without_censorship: l10n.translate("federated-services-without-censorship").unwrap(),
|
i18n_federated_services_without_censorship: l10n.translate("federated-services-without-censorship")?,
|
||||||
};
|
};
|
||||||
|
|
||||||
let context = views::Site {
|
let context = views::Site {
|
||||||
|
|
Reference in New Issue