Enum perseus::error_views::ErrorContext
source · pub enum ErrorContext {
Static,
WithReactor,
FullNoGlobal,
Full,
}
Expand description
The context of an error, which determines what is available to your views. This must be checked before using things like translators, which may not be available, depending on the information in here.
Variants§
Static
Perseus has suffered an unrecoverable error in initialization, and routing/interactivity is impossible. Your error view will be rendered to the page, and then Perseus will terminate completely. This means any buttons, handlers, etc. will not run!
If you’re having trouble with this, imagine printing out your error
view. That’s the amount of functionality you get (except that the
browser will automatically take over any links). If you want
interactivity, you could use dangerously_set_inner_html
to create
some JS handlers, for instance for offering the user a button to
reload the page.
WithReactor
Perseus suffered an error before it was able to create a translator.
Your error view will be rendered inside a proper router, and you’ll
have a Reactor
available in context, but using the t!
or
link!
macros will lead to a panic. If you present links to other pages
in the app, the user will be able to press them, and these will try
to set up a translator, but this may fail.
If your app doesn’t use internationalization, Perseus does still have a dummy translator internally, so this doesn’t completely evaporate, but you can ignore it.
Note: currently, if the user goes to, say
/en-US/this-page-does-not-exist
, even though the page is clearly
localized, Perseus will not provide a translator. This will be rectified
in a future version. If the user attempted to switch locales, and
there was an error fetching translations for the new one, the old
translator will be provided here.
FullNoGlobal
Perseus was able to successfully instantiate a reactor and translator, but this error view is being rendered on the engine-side, and there is no global state available.
Although global state could theoretically be provided to error pages sometimes, the complexity and cloning involved make this extremely nuanced (e.g. exported error pages can’t access localized global state because they don’t know their locale, global state might be only partially built at the time of the error, etc.). In general, error views rendered on the engine-side will have this (though not always).
Full
Perseus was able to successfully instantiate everything, including a translator, but then it encountered an error. You have access to all the usual things you would have in a page here.
Note that this would also be given to you on the engine-side when you
have a translator available, but when you’re still rendering to an
[SsrNode
].
Trait Implementations§
source§impl Clone for ErrorContext
impl Clone for ErrorContext
source§fn clone(&self) -> ErrorContext
fn clone(&self) -> ErrorContext
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more