From 82d3473709d14ff2697b3e8c46a9919763d578c7 Mon Sep 17 00:00:00 2001 From: realaravinth Date: Tue, 4 May 2021 11:49:48 +0000 Subject: [PATCH] =?UTF-8?q?Deploying=20to=20gh-pages=20from=20=20@=203ac95?= =?UTF-8?q?e100534706be04a6eba784e1ca34c6fdbcd=20=F0=9F=9A=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- guard/all.html | 2 +- guard/constant.PAGES.html | 2 +- guard/errors/constant.PAGE.html | 5 - guard/errors/enum.PageError.html | 6 +- guard/errors/index.html | 9 +- guard/errors/sidebar-items.js | 2 +- guard/errors/type.PageResult.html | 2 +- guard/pages/constant.NAME.html | 2 +- guard/pages/errors/constant.PAGE.html | 5 + guard/pages/errors/fn.error.html | 5 + guard/pages/errors/fn.services.html | 5 + guard/pages/errors/index.html | 9 + guard/pages/errors/routes/index.html | 6 + guard/pages/errors/routes/sidebar-items.js | 1 + guard/pages/errors/routes/struct.Errors.html | 116 +++++++++ guard/pages/errors/sidebar-items.js | 1 + .../{ => pages}/errors/struct.ErrorPage.html | 20 +- .../struct.INTERNAL_SERVER_ERROR_BODY.html} | 18 +- .../errors/struct.UNKNOWN_ERROR_BODY.html} | 18 +- guard/pages/fn.services.html | 2 +- guard/pages/index.html | 4 +- guard/pages/routes/constant.ROUTES.html | 2 +- guard/pages/routes/index.html | 2 +- guard/pages/routes/struct.Routes.html | 7 +- guard/pages/sidebar-items.js | 2 +- implementors/core/clone/trait.Clone.js | 2 +- implementors/core/marker/trait.Freeze.js | 2 +- implementors/core/marker/trait.Send.js | 2 +- implementors/core/marker/trait.Sync.js | 2 +- implementors/core/marker/trait.Unpin.js | 2 +- implementors/core/ops/deref/trait.Deref.js | 2 +- implementors/lazy_static/trait.LazyStatic.js | 2 +- implementors/sailfish/private/trait.Sealed.js | 2 +- implementors/sailfish/trait.TemplateOnce.js | 2 +- implementors/std/panic/trait.RefUnwindSafe.js | 2 +- implementors/std/panic/trait.UnwindSafe.js | 2 +- search-index.js | 2 +- source-files.js | 2 +- src/guard/errors.rs.html | 82 ++---- src/guard/pages/errors.rs.html | 245 ++++++++++++++++++ src/guard/pages/mod.rs.html | 4 + src/guard/pages/routes.rs.html | 6 + 42 files changed, 484 insertions(+), 132 deletions(-) delete mode 100644 guard/errors/constant.PAGE.html create mode 100644 guard/pages/errors/constant.PAGE.html create mode 100644 guard/pages/errors/fn.error.html create mode 100644 guard/pages/errors/fn.services.html create mode 100644 guard/pages/errors/index.html create mode 100644 guard/pages/errors/routes/index.html create mode 100644 guard/pages/errors/routes/sidebar-items.js create mode 100644 guard/pages/errors/routes/struct.Errors.html create mode 100644 guard/pages/errors/sidebar-items.js rename guard/{ => pages}/errors/struct.ErrorPage.html (85%) rename guard/{errors/struct.UNKNOWN_ERROR.html => pages/errors/struct.INTERNAL_SERVER_ERROR_BODY.html} (95%) rename guard/{errors/struct.INTERNAL_SERVER_ERROR.html => pages/errors/struct.UNKNOWN_ERROR_BODY.html} (95%) create mode 100644 src/guard/pages/errors.rs.html diff --git a/guard/all.html b/guard/all.html index 515e4e8d..21e55181 100644 --- a/guard/all.html +++ b/guard/all.html @@ -3,5 +3,5 @@

List of all items[] -

Structs

Enums

Macros

Functions

Typedefs

Statics

Constants

+

Structs

Enums

Macros

Functions

Typedefs

Statics

Constants

\ No newline at end of file diff --git a/guard/constant.PAGES.html b/guard/constant.PAGES.html index af2ef2b1..f86e4c8c 100644 --- a/guard/constant.PAGES.html +++ b/guard/constant.PAGES.html @@ -1,5 +1,5 @@ guard::PAGES - Rust

Constant guard::PAGES[][src]

pub const PAGES: Routes;
+ Change settings

Constant guard::PAGES[][src]

pub const PAGES: Routes;
\ No newline at end of file diff --git a/guard/errors/constant.PAGE.html b/guard/errors/constant.PAGE.html deleted file mode 100644 index b8ed6c21..00000000 --- a/guard/errors/constant.PAGE.html +++ /dev/null @@ -1,5 +0,0 @@ -guard::errors::PAGE - Rust - -

Constant guard::errors::PAGE[][src]

const PAGE: &str = "Error";
- \ No newline at end of file diff --git a/guard/errors/enum.PageError.html b/guard/errors/enum.PageError.html index 0c5091b4..adbd6a09 100644 --- a/guard/errors/enum.PageError.html +++ b/guard/errors/enum.PageError.html @@ -13,12 +13,12 @@

impl From<Error> for PageError[src]

impl From<Error> for PageError[src]

impl PartialEq<PageError> for PageError[src]

impl ResponseError for PageError[src]

impl ResponseError for PageError[src]

impl StructuralPartialEq for PageError[src]

Auto Trait Implementations

impl RefUnwindSafe for PageError[src]

impl Send for PageError[src]

impl Sync for PageError[src]

impl Unpin for PageError[src]

impl UnwindSafe for PageError[src]

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

Type Definition guard::errors::PageResult[][src]

type PageResult<V> = Result<V, PageError>;
\ No newline at end of file diff --git a/guard/pages/constant.NAME.html b/guard/pages/constant.NAME.html index 5bce858b..870c9720 100644 --- a/guard/pages/constant.NAME.html +++ b/guard/pages/constant.NAME.html @@ -1,5 +1,5 @@ guard::pages::NAME - Rust

Constant guard::pages::NAME[][src]

pub const NAME: &str = "mCaptcha";
+ Change settings

Constant guard::pages::NAME[][src]

pub const NAME: &str = "mCaptcha";
\ No newline at end of file diff --git a/guard/pages/errors/constant.PAGE.html b/guard/pages/errors/constant.PAGE.html new file mode 100644 index 00000000..f4460b62 --- /dev/null +++ b/guard/pages/errors/constant.PAGE.html @@ -0,0 +1,5 @@ +guard::pages::errors::PAGE - Rust + +

Constant guard::pages::errors::PAGE[][src]

const PAGE: &str = "Error";
+ \ No newline at end of file diff --git a/guard/pages/errors/fn.error.html b/guard/pages/errors/fn.error.html new file mode 100644 index 00000000..1db5e797 --- /dev/null +++ b/guard/pages/errors/fn.error.html @@ -0,0 +1,5 @@ +guard::pages::errors::error - Rust + +

Function guard::pages::errors::error[][src]

async fn error(path: Path<usize>) -> impl Responder
+ \ No newline at end of file diff --git a/guard/pages/errors/fn.services.html b/guard/pages/errors/fn.services.html new file mode 100644 index 00000000..a5ef435f --- /dev/null +++ b/guard/pages/errors/fn.services.html @@ -0,0 +1,5 @@ +guard::pages::errors::services - Rust + +

Function guard::pages::errors::services[][src]

pub fn services(cfg: &mut ServiceConfig)
+ \ No newline at end of file diff --git a/guard/pages/errors/index.html b/guard/pages/errors/index.html new file mode 100644 index 00000000..a516eef4 --- /dev/null +++ b/guard/pages/errors/index.html @@ -0,0 +1,9 @@ +guard::pages::errors - Rust + +

Module guard::pages::errors[][src]

Modules

+
routes

Structs

+
ErrorPage
INTERNAL_SERVER_ERROR_BODY
UNKNOWN_ERROR_BODY

Constants

+
PAGE

Functions

+
error
services
+ \ No newline at end of file diff --git a/guard/pages/errors/routes/index.html b/guard/pages/errors/routes/index.html new file mode 100644 index 00000000..151e3996 --- /dev/null +++ b/guard/pages/errors/routes/index.html @@ -0,0 +1,6 @@ +guard::pages::errors::routes - Rust + +

Module guard::pages::errors::routes[][src]

Structs

+
Errors
+ \ No newline at end of file diff --git a/guard/pages/errors/routes/sidebar-items.js b/guard/pages/errors/routes/sidebar-items.js new file mode 100644 index 00000000..6391170d --- /dev/null +++ b/guard/pages/errors/routes/sidebar-items.js @@ -0,0 +1 @@ +initSidebarItems({"struct":[["Errors",""]]}); \ No newline at end of file diff --git a/guard/pages/errors/routes/struct.Errors.html b/guard/pages/errors/routes/struct.Errors.html new file mode 100644 index 00000000..5e4e8eac --- /dev/null +++ b/guard/pages/errors/routes/struct.Errors.html @@ -0,0 +1,116 @@ +guard::pages::errors::routes::Errors - Rust + +

Struct guard::pages::errors::routes::Errors[][src]

pub struct Errors {
+    pub internal_server_error: &'static str,
+    pub unknown_error: &'static str,
+}

+ Fields

internal_server_error: &'static strunknown_error: &'static str

Implementations

impl Errors[src]

pub const fn new() -> Self[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Conv for T

impl<T> Conv for T

impl<T> FmtForward for T

impl<T> From<T> for T[src]

impl<T> Instrument for T[src]

impl<T> Instrument for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Pipe for T where
    T: ?Sized

impl<T> Pipe for T

impl<T> PipeAsRef for T

impl<T> PipeBorrow for T

impl<T> PipeDeref for T

impl<T> PipeRef for T

impl<T> Same<T> for T

type Output = T

Should always be Self

+

impl<T> Tap for T

impl<T> Tap for T

impl<T, U> TapAsRef<U> for T where
    U: ?Sized

impl<T, U> TapBorrow<U> for T where
    U: ?Sized

impl<T> TapDeref for T

impl<T> TryConv for T

impl<T> TryConv for T

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

+

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

+

impl<V, T> VZip<V> for T where
    V: MultiLane<T>, 

+ \ No newline at end of file diff --git a/guard/pages/errors/sidebar-items.js b/guard/pages/errors/sidebar-items.js new file mode 100644 index 00000000..49e742a1 --- /dev/null +++ b/guard/pages/errors/sidebar-items.js @@ -0,0 +1 @@ +initSidebarItems({"constant":[["PAGE",""]],"fn":[["error",""],["services",""]],"mod":[["routes",""]],"struct":[["ErrorPage",""],["INTERNAL_SERVER_ERROR_BODY",""],["UNKNOWN_ERROR_BODY",""]]}); \ No newline at end of file diff --git a/guard/errors/struct.ErrorPage.html b/guard/pages/errors/struct.ErrorPage.html similarity index 85% rename from guard/errors/struct.ErrorPage.html rename to guard/pages/errors/struct.ErrorPage.html index d6e552e8..d68e14b2 100644 --- a/guard/errors/struct.ErrorPage.html +++ b/guard/pages/errors/struct.ErrorPage.html @@ -1,15 +1,15 @@ -guard::errors::ErrorPage - Rust - -

Struct guard::errors::ErrorPage[][src]

struct ErrorPage<'a> {
+guard::pages::errors::ErrorPage - Rust
+
+

Struct guard::pages::errors::ErrorPage[][src]

struct ErrorPage<'a> {
     title: &'a str,
     message: &'a str,
 }

- Fields

title: &'a strmessage: &'a str

Implementations

impl<'a> ErrorPage<'a>[src]

fn new(title: &'a str, message: &'a str) -> Self[src]

Trait Implementations

impl<'a> Clone for ErrorPage<'a>[src]

- \ No newline at end of file +

impl<V, T> VZip<V> for T where
    V: MultiLane<T>, 

+ \ No newline at end of file diff --git a/guard/errors/struct.UNKNOWN_ERROR.html b/guard/pages/errors/struct.INTERNAL_SERVER_ERROR_BODY.html similarity index 95% rename from guard/errors/struct.UNKNOWN_ERROR.html rename to guard/pages/errors/struct.INTERNAL_SERVER_ERROR_BODY.html index 1a34ee82..46009756 100644 --- a/guard/errors/struct.UNKNOWN_ERROR.html +++ b/guard/pages/errors/struct.INTERNAL_SERVER_ERROR_BODY.html @@ -1,7 +1,7 @@ -guard::errors::UNKNOWN_ERROR - Rust - -

Struct guard::errors::UNKNOWN_ERROR[][src]

struct UNKNOWN_ERROR {
+guard::pages::errors::INTERNAL_SERVER_ERROR_BODY - Rust
+
+

Struct guard::pages::errors::INTERNAL_SERVER_ERROR_BODY[][src]

struct INTERNAL_SERVER_ERROR_BODY {
     __private_field: (),
 }

Fields

__private_field: ()

Methods from Deref<Target = String>

pub fn as_str(&self) -> &str1.7.0[src]

Extracts a string slice containing the entire String.

@@ -1442,9 +1442,9 @@ but non-ASCII letters are unchanged.

let s = "Grüße, Jürgen ❤"; assert_eq!("grüße, jürgen ❤", s.to_ascii_lowercase());
-

Trait Implementations

impl Deref for UNKNOWN_ERROR[src]

type Target = String

The resulting type after dereferencing.

-

impl LazyStatic for UNKNOWN_ERROR[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

Trait Implementations

impl Deref for INTERNAL_SERVER_ERROR_BODY[src]

type Target = String

The resulting type after dereferencing.

+

impl LazyStatic for INTERNAL_SERVER_ERROR_BODY[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Conv for T

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>, 

- \ No newline at end of file +

impl<V, T> VZip<V> for T where
    V: MultiLane<T>, 

+ \ No newline at end of file diff --git a/guard/errors/struct.INTERNAL_SERVER_ERROR.html b/guard/pages/errors/struct.UNKNOWN_ERROR_BODY.html similarity index 95% rename from guard/errors/struct.INTERNAL_SERVER_ERROR.html rename to guard/pages/errors/struct.UNKNOWN_ERROR_BODY.html index 2df226fd..194a1da7 100644 --- a/guard/errors/struct.INTERNAL_SERVER_ERROR.html +++ b/guard/pages/errors/struct.UNKNOWN_ERROR_BODY.html @@ -1,7 +1,7 @@ -guard::errors::INTERNAL_SERVER_ERROR - Rust - -

Struct guard::errors::INTERNAL_SERVER_ERROR[][src]

struct INTERNAL_SERVER_ERROR {
+guard::pages::errors::UNKNOWN_ERROR_BODY - Rust
+
+

Struct guard::pages::errors::UNKNOWN_ERROR_BODY[][src]

struct UNKNOWN_ERROR_BODY {
     __private_field: (),
 }

Fields

__private_field: ()

Methods from Deref<Target = String>

pub fn as_str(&self) -> &str1.7.0[src]

Extracts a string slice containing the entire String.

@@ -1442,9 +1442,9 @@ but non-ASCII letters are unchanged.

let s = "Grüße, Jürgen ❤"; assert_eq!("grüße, jürgen ❤", s.to_ascii_lowercase());
-

Trait Implementations

impl Deref for INTERNAL_SERVER_ERROR[src]

type Target = String

The resulting type after dereferencing.

-

impl LazyStatic for INTERNAL_SERVER_ERROR[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

Trait Implementations

impl Deref for UNKNOWN_ERROR_BODY[src]

type Target = String

The resulting type after dereferencing.

+

impl LazyStatic for UNKNOWN_ERROR_BODY[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Conv for T

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>, 

- \ No newline at end of file +

impl<V, T> VZip<V> for T where
    V: MultiLane<T>, 

+ \ No newline at end of file diff --git a/guard/pages/fn.services.html b/guard/pages/fn.services.html index 90d09ade..caad0b13 100644 --- a/guard/pages/fn.services.html +++ b/guard/pages/fn.services.html @@ -1,5 +1,5 @@ guard::pages::services - Rust

Function guard::pages::services[][src]

pub fn services(cfg: &mut ServiceConfig)
+ Change settings

Function guard::pages::services[][src]

pub fn services(cfg: &mut ServiceConfig)
\ No newline at end of file diff --git a/guard/pages/index.html b/guard/pages/index.html index 97dea5d3..ff199593 100644 --- a/guard/pages/index.html +++ b/guard/pages/index.html @@ -1,8 +1,8 @@ guard::pages - Rust

Module guard::pages[][src]

Modules

-
auth
panel
routes

Constants

+ Change settings

Module guard::pages[][src]

Modules

+
auth
errors
panel
routes

Constants

NAME

Functions

services
\ No newline at end of file diff --git a/guard/pages/routes/constant.ROUTES.html b/guard/pages/routes/constant.ROUTES.html index 92351854..90b266f0 100644 --- a/guard/pages/routes/constant.ROUTES.html +++ b/guard/pages/routes/constant.ROUTES.html @@ -1,5 +1,5 @@ guard::pages::routes::ROUTES - Rust

Constant guard::pages::routes::ROUTES[][src]

pub const ROUTES: Routes;
+ Change settings

Constant guard::pages::routes::ROUTES[][src]

pub const ROUTES: Routes;
\ No newline at end of file diff --git a/guard/pages/routes/index.html b/guard/pages/routes/index.html index a70ffdbd..7ea94adc 100644 --- a/guard/pages/routes/index.html +++ b/guard/pages/routes/index.html @@ -1,7 +1,7 @@ guard::pages::routes - Rust

Module guard::pages::routes[][src]

Structs

+ Change settings

Module guard::pages::routes[][src]

Structs

Routes

Constants

ROUTES
\ No newline at end of file diff --git a/guard/pages/routes/struct.Routes.html b/guard/pages/routes/struct.Routes.html index 398fc194..54e84500 100644 --- a/guard/pages/routes/struct.Routes.html +++ b/guard/pages/routes/struct.Routes.html @@ -1,12 +1,13 @@ guard::pages::routes::Routes - Rust -

Struct guard::pages::routes::Routes[][src]

pub struct Routes {
+

Struct guard::pages::routes::Routes[][src]

pub struct Routes {
     pub home: &'static str,
     pub auth: Auth,
     pub panel: Panel,
+    pub errors: Errors,
 }

- Fields

home: &'static strauth: Authpanel: Panel

Implementations

impl Routes[src]

const fn new() -> Routes[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

 /*
 * Copyright (C) 2021  Aravinth Manivannan <realaravinth@batsense.net>
@@ -475,38 +452,6 @@
     InternalServerError,
 }
 
-use sailfish::TemplateOnce;
-
-#[derive(Clone, TemplateOnce)]
-#[template(path = "errors/internal-server-error.html")]
-struct ErrorPage<'a> {
-    title: &'a str,
-    message: &'a str,
-}
-
-const PAGE: &str = "Error";
-
-impl<'a> ErrorPage<'a> {
-    fn new(title: &'a str, message: &'a str) -> Self {
-        ErrorPage { title, message }
-    }
-}
-
-lazy_static! {
-    static ref INTERNAL_SERVER_ERROR: String = ErrorPage::new(
-        "Internal Server Error",
-        &format!("{}", PageError::InternalServerError)
-    )
-    .render_once()
-    .unwrap();
-    static ref UNKNOWN_ERROR: String = ErrorPage::new(
-        "Server Error",
-        &format!("{}", PageError::InternalServerError)
-    )
-    .render_once()
-    .unwrap();
-}
-
 #[cfg(not(tarpaulin_include))]
 impl From<sqlx::Error> for PageError {
     #[cfg(not(tarpaulin_include))]
@@ -516,15 +461,18 @@
 }
 
 impl ResponseError for PageError {
-    #[cfg(not(tarpaulin_include))]
     fn error_response(&self) -> HttpResponse {
-        let body = match self.status_code() {
-            StatusCode::INTERNAL_SERVER_ERROR => &*INTERNAL_SERVER_ERROR,
-            _ => &*UNKNOWN_ERROR,
-        };
-        HttpResponseBuilder::new(self.status_code())
-            .content_type("text/html; charset=utf-8")
-            .body(body)
+        use crate::PAGES;
+        match self.status_code() {
+            StatusCode::INTERNAL_SERVER_ERROR => HttpResponse::Found()
+                .header(header::LOCATION, PAGES.errors.internal_server_error)
+                .finish()
+                .into(),
+            _ => HttpResponse::Found()
+                .header(header::LOCATION, PAGES.errors.unknown_error)
+                .finish()
+                .into(),
+        }
     }
 
     #[cfg(not(tarpaulin_include))]
@@ -541,11 +489,17 @@
 #[cfg(test)]
 mod tests {
     use super::*;
+    use crate::PAGES;
 
     #[test]
     fn error_works() {
         let resp: HttpResponse = PageError::InternalServerError.error_response();
-        assert_eq!(resp.status(), StatusCode::INTERNAL_SERVER_ERROR);
+        assert_eq!(resp.status(), StatusCode::FOUND);
+        let headers = resp.headers();
+        assert_eq!(
+            headers.get(header::LOCATION).unwrap(),
+            PAGES.errors.internal_server_error
+        );
     }
 }
 
diff --git a/src/guard/pages/errors.rs.html b/src/guard/pages/errors.rs.html new file mode 100644 index 00000000..210e5a49 --- /dev/null +++ b/src/guard/pages/errors.rs.html @@ -0,0 +1,245 @@ +errors.rs - source + +
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+ 28
+ 29
+ 30
+ 31
+ 32
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+ 41
+ 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+
+/*
+* Copyright (C) 2021  Aravinth Manivannan <realaravinth@batsense.net>
+*
+* This program is free software: you can redistribute it and/or modify
+* it under the terms of the GNU Affero General Public License as
+* published by the Free Software Foundation, either version 3 of the
+* License, or (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+* GNU Affero General Public License for more details.
+*
+* You should have received a copy of the GNU Affero General Public License
+* along with this program.  If not, see <https://www.gnu.org/licenses/>.
+*/
+
+use actix_web::{web, HttpResponse, Responder};
+use lazy_static::lazy_static;
+use sailfish::TemplateOnce;
+
+use crate::errors::PageError;
+
+#[derive(Clone, TemplateOnce)]
+#[template(path = "errors/index.html")]
+struct ErrorPage<'a> {
+    title: &'a str,
+    message: &'a str,
+}
+
+const PAGE: &str = "Error";
+
+impl<'a> ErrorPage<'a> {
+    fn new(title: &'a str, message: &'a str) -> Self {
+        ErrorPage { title, message }
+    }
+}
+
+lazy_static! {
+    static ref INTERNAL_SERVER_ERROR_BODY: String = ErrorPage::new(
+        "Internal Server Error",
+        &format!("{}", PageError::InternalServerError),
+    )
+    .render_once()
+    .unwrap();
+    static ref UNKNOWN_ERROR_BODY: String = ErrorPage::new(
+        "Something went wrong",
+        &format!("{}", PageError::InternalServerError),
+    )
+    .render_once()
+    .unwrap();
+}
+
+async fn error(path: web::Path<usize>) -> impl Responder {
+    let resp = match path.0 {
+        500 => HttpResponse::InternalServerError()
+            .content_type("text/html; charset=utf-8")
+            .body(&*INTERNAL_SERVER_ERROR_BODY),
+
+        _ => HttpResponse::InternalServerError()
+            .content_type("text/html; charset=utf-8")
+            .body(&*UNKNOWN_ERROR_BODY),
+    };
+
+    resp
+}
+
+pub fn services(cfg: &mut web::ServiceConfig) {
+    use crate::define_resource;
+
+    define_resource!(cfg, "/error/{id}", Methods::Get, error);
+}
+
+pub mod routes {
+    pub struct Errors {
+        pub internal_server_error: &'static str,
+        pub unknown_error: &'static str,
+    }
+
+    impl Errors {
+        pub const fn new() -> Self {
+            Errors {
+                internal_server_error: "/error/500",
+                unknown_error: "/error/007",
+            }
+        }
+    }
+}
+
+#[cfg(test)]
+mod tests {
+    use actix_web::{http::StatusCode, test, App};
+
+    use super::*;
+    use crate::PAGES;
+
+    #[actix_rt::test]
+    async fn error_pages_work() {
+        let mut app = test::init_service(App::new().configure(services)).await;
+
+        let resp = test::call_service(
+            &mut app,
+            test::TestRequest::get()
+                .uri(PAGES.errors.internal_server_error)
+                .to_request(),
+        )
+        .await;
+        assert_eq!(resp.status(), StatusCode::INTERNAL_SERVER_ERROR);
+
+        let resp = test::call_service(
+            &mut app,
+            test::TestRequest::get()
+                .uri(PAGES.errors.unknown_error)
+                .to_request(),
+        )
+        .await;
+        assert_eq!(resp.status(), StatusCode::INTERNAL_SERVER_ERROR);
+    }
+}
+
+
+ \ No newline at end of file diff --git a/src/guard/pages/mod.rs.html b/src/guard/pages/mod.rs.html index ce0e9cdf..287e5764 100644 --- a/src/guard/pages/mod.rs.html +++ b/src/guard/pages/mod.rs.html @@ -103,6 +103,8 @@ 100 101 102 +103 +104
 /*
 * Copyright (C) 2021  Aravinth Manivannan <realaravinth@batsense.net>
@@ -124,6 +126,7 @@
 use actix_web::web::ServiceConfig;
 
 mod auth;
+pub mod errors;
 mod panel;
 pub mod routes;
 
@@ -132,6 +135,7 @@
 pub fn services(cfg: &mut ServiceConfig) {
     auth::services(cfg);
     panel::services(cfg);
+    errors::services(cfg);
 }
 
 #[cfg(not(tarpaulin_include))]
diff --git a/src/guard/pages/routes.rs.html b/src/guard/pages/routes.rs.html
index aecdca0f..1fec7253 100644
--- a/src/guard/pages/routes.rs.html
+++ b/src/guard/pages/routes.rs.html
@@ -39,6 +39,9 @@
 36
 37
 38
+39
+40
+41
 
 /*
 * Copyright (C) 2021  Aravinth Manivannan <realaravinth@batsense.net>
@@ -58,6 +61,7 @@
 */
 
 use super::auth::routes::Auth;
+use super::errors::routes::Errors;
 use super::panel::routes::Panel;
 pub const ROUTES: Routes = Routes::new();
 
@@ -65,6 +69,7 @@
     pub home: &'static str,
     pub auth: Auth,
     pub panel: Panel,
+    pub errors: Errors,
 }
 
 impl Routes {
@@ -75,6 +80,7 @@
             auth: Auth::new(),
             panel,
             home,
+            errors: Errors::new(),
         }
     }
 }