|
|
|
|
Foswiki::OopsExceptionChanged by ProjectContributor on 12 Sep 2009 - 04:10 - r1
package Foswiki::OopsExceptionException used to raise a request to output a preformatted page.
Despite the name,
The
Extensions may throw
use Error qw(:try); ... throw Foswiki::OopsException( 'bathplugin', status => 418, web => $web, topic => $topic, params => [ 'big toe', 'stuck in', 'hot tap' ] );This will raise an exception that uses the bathplugin.tmpl template. If
UI::run handles the exception it will generate a redirect to:
oops?template=bathplugin;param1=bigtoe;param2=hot%20tapThe bathplugin.tmpl might contain:
%TMPL:INCLUDE{"oops"}% %TMPL:DEF{"titleaction"}% %MAKETEXT{"Bathing problem"}% %TMPL:END% %TMPL:DEF{"heading"}%%MAKETEXT{"Problem filling bath"}%%TMPL:END% %TMPL:DEF{"topicactionbuttons"}%%TMPL:P{"oktopicaction"}%%TMPL:END% %TMPL:DEF{"script"}%<meta http-equiv="refresh" content="0;url=%SCRIPTURL{view}%/%WEB%/%TOPIC%" />%TMPL:END% %TMPL:DEF{"pagetitle"}%%TMPL:P{"heading"}%%TMPL:END% %TMPL:DEF{"webaction"}% *%MAKETEXT{"Warning"}%* %TMPL:END% %TMPL:DEF{"message"}% %MAKETEXT{"Your bath cannot be filled because your [_1] is [_2] the [_3]%TMPL:END%In this case the oops page will be rendered with a 418 ("I'm a teapot")
status in the HTTP header.
A more practical example for plugins authors that does not require them to
provide their own template file involves use of the generic message template
available from throw Foswiki::OopsException( 'oopsattention', def => 'generic', params => [ Operation is not allowed ] ); Note that to protect against cross site scripting all parameter values are automatically and unconditionally entity-encoded so you cannot pass macros if you need messages to be automatically translated you either need to handle it in the perl code before throwing Foswiki::OopsException or put the %MAKETEXT in the template. You cannot pass macros through the parameters. API version $Date: 2009-12-11 10:25:14 +0100 (Fri, 11 Dec 2009) $ (revision $Rev: 6075 (2010-01-17) $) Since date indicates where functions or parameters have been added since the baseline of the API (TWiki release 4.2.3). The date indicates the earliest date of a Foswiki release that will support that function or parameter. Deprecated date indicates where a function or parameters has been deprecated. Deprecated functions will still work, though they should not be called in new plugins and should be replaced in older plugins as soon as possible. Deprecated parameters are simply ignored in Foswiki releases after date. Until date indicates where a function or parameter has been removed. The date indicates the latest date at which Foswiki releases still supported the function or parameter.
ClassMethod new( $template, ...)
For an example of how to use the NOTE: parameter values are automatically and unconditionally entity-encoded so you cannot pass macros
ObjectMethod stringify( [$session] ) -> $stringGenerates a string representation for the object. if a session is passed in, and the exception specifies a def, then that def is expanded. This is to allow internal expansion of oops exceptions for example when performing bulk operations, and also for debugging.
ObjectMethod generate( $session )
Generate an error page for the exception. This will output the error page
to the browser. The default HTTP Status for an Oops page is 500. This
can be overridden using the 'status => ' parameter to the constructor.
|