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