pub struct ErrorViews<G: Html> { /* private fields */ }
Expand description

The error handling system of an app. In Perseus, errors come in several forms, all of which must be handled. This system provides a way to do this automatically, maximizing your app’s error tolerance, including against panics.

Implementations§

source§

impl<G: Html> ErrorViews<G>

source

pub fn new( handler: impl Fn(Scope<'_>, ClientError, ErrorContext, ErrorPosition) -> (View<SsrNode>, View<G>) + Send + Sync + Clone + 'static ) -> Self

Creates an error handling system for your app with the given handler function. This will be provided a ClientError to match against, along with an ErrorContext, which tells you what you have available to you (since, in some critical errors, you might not even have a translator).

The function given to this should return a tuple of two Views: the first to be placed in document <head>, and the second for the body. For views with ErrorPosition::Popup or ErrorPosition::Widget, the head view will be ignored, and would usually be returned as View::empty().

source

pub fn subsequent_load_determinant_fn( &mut self, val: impl Fn(&ClientError) -> bool + Send + Sync + 'static ) -> &mut Self

Sets the function that determines if an error on a subsequent load should be presented to the user as taking up the whole page, or just being in a little popup. Usually, you can leave this as the default, which will display any internal errors as popups, and any errors from the server (e.g. a 404 not found) as full pages.

You could use this to create extremely unorthodox patterns like rendering a popup on the current page if the user clicks a link that goes to a 404, if you really wanted.

For widgets, returning true from the function you provide to this will take up the whole widget, as opposed to the whole page.

Note: if you want all your errors to take up the whole page no matter what (not recommended, see the book for why!), you should leave this function as the default and simply style #__perseus_error_popup to take up the whole page.

source

pub fn unlocalized_development_default() -> Self

Force-sets the unlocalized defaults. If you really want to use the default error pages in production, this will allow you to (where they would normally fail if you simply specified nothing).

Warning: these defaults are completely unlocalized, unstyled, and intended for development! You will be able to use these by not specifying any .error_views() on your PerseusApp in development, and you should only use this function if you’re doing production testing of Perseus, and you don’t particularly want to write your own error pages.

Note that this is used throughout the Perseus examples for brevity.

Trait Implementations§

source§

impl<G: Html> Debug for ErrorViews<G>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<G: Html> Default for ErrorViews<G>

source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<G> !RefUnwindSafe for ErrorViews<G>

§

impl<G> Send for ErrorViews<G>

§

impl<G> Sync for ErrorViews<G>

§

impl<G> Unpin for ErrorViews<G>

§

impl<G> !UnwindSafe for ErrorViews<G>

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.