public package Foswiki::OopsException

See PublishedAPI for packages intended to be used by Plugin and Contrib authors, or browse all packages.
See also Developing plugins, Developer's Bible, Technical Overview

public package Foswiki::OopsException is a Error

Exception used to raise a request to output a preformatted page.

Despite the name, oops is not used just for errors; it is also used for one-time redirection, for example during the registration process.

The Foswiki::UI::run function, which is in the call stack for almost all cases where an OopsException will be thrown, traps the exception and outputs an oops page to the browser. This requires the name of a template file from the templates directory, which it expands. (The passed template name is prefixed with "oops", as shown below.)

Parameter values passed to the exception are instantiated in the expanded template. The oops page is output with an HTTP status appropriate to the event that caused the exception (default 500).

Extensions may throw Foswiki::OopsException. For example:

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 oopsbathplugin.tmpl template. If UI::run handles the exception it will generate a redirect to:
oops?template=oopsbathplugin;param1=bigtoe;param2=hot%20tap
The oopsbathplugin.tmpl might contain: (<nop> inserted to prevent translation interface from extracting these examples)
%TMPL:INCLUDE{"oops"}%
%TMPL:DEF{"titleaction"}% %<nop>MAKETEXT{"Bathing problem"}% %TMPL:END%
%TMPL:DEF{"heading"}%%<nop>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"}% *%<nop>MAKETEXT{"Warning"}%* %TMPL:END%
%TMPL:DEF{"message"}%
%<nop>MAKETEXT{"Your bath cannot be filled because your [_1] is [_2] the [_3]" args="drain,flooding,basement"}%%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 oopsattention.tmpl:
throw Foswiki::OopsException( 'attention', 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.

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, …)

  • template is the name of an oops template. e.g. 'bathplugin' refers to templates/oopsbathplugin.tmpl
The remaining parameters are interpreted as key-value pairs. The following keys are used:
  • web will be used as the web for the oops
  • topic will be used as the topic for the oops
  • def - is the (optional) name of a TMPL:DEF within the template
  • keep - if set, the exception handler should try its damnedest to retain parameter values from the query.
  • params is a reference to an array of parameters. These will be substituted for %PARAM1%, %PARAM2% … %PARAMn% in the template.

For an example of how to use the def parameter, see the oopsattention template.

NOTE: parameter values are automatically and unconditionally entity-encoded

ObjectMethod stringify( [$session] ) → $string

Generates 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.

This site is powered by FoswikiCopyright © by the contributing authors. All material on this site is the property of the contributing authors.
Ideas, requests, problems regarding Wasserstoff-Fahrer Forum? Send feedback
This website is using cookies. More info. That's Fine