Struct perseus::error_views::ErrorViews
source · 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>
impl<G: Html> ErrorViews<G>
sourcepub fn new(
handler: impl Fn(Scope<'_>, ClientError, ErrorContext, ErrorPosition) -> (View<SsrNode>, View<G>) + Send + Sync + Clone + 'static
) -> Self
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 View
s: 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()
.
sourcepub fn subsequent_load_determinant_fn(
&mut self,
val: impl Fn(&ClientError) -> bool + Send + Sync + 'static
) -> &mut Self
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.
sourcepub fn unlocalized_development_default() -> Self
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.