Ignore:
Timestamp:
12/02/08 12:49:15 (3 years ago)
Author:
CrawfordCurrie
Message:

Item139: removed oops redirect for error reports. Fixed status header in HTTP responses.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/core/lib/Foswiki/OopsException.pm

    r1050 r1127  
    2424 
    2525throw Foswiki::OopsException( 'bathplugin', 
     26                            status => 418, 
    2627                            def => 'toestuck', 
    2728                            web => $web, 
     
    8485    my $class    = shift; 
    8586    my $template = shift; 
    86     my $this     = bless( $class->SUPER::new(), $class ); 
     87    my $this     = $class->SUPER::new(); 
    8788    $this->{template} = $template; 
    8889    ASSERT( scalar(@_) % 2 == 0, join( ";", map { $_ || 'undef' } @_ ) ) 
     
    146147} 
    147148 
    148 =begin TML 
    149  
    150 ---++ ObjectMethod redirect( $twiki ) 
    151  
    152 Generate a redirect to an 'oops' script for this exception. 
    153  
    154 If the 'keep' parameter is set in the 
    155 exception, it saves parameter values into the query as well. This is needed 
    156 if the query string might get lost during a passthrough, due to a POST 
    157 being redirected to a GET. 
    158  
    159 =cut 
    160  
     149# Generate a redirect to an 'oops' script for this exception. 
     150# 
     151# If the 'keep' parameter is set in the 
     152# exception, it saves parameter values into the query as well. This is needed 
     153# if the query string might get lost during a passthrough, due to a POST 
     154# being redirected to a GET. 
     155# This redirect has been replaced by the generate function below and should 
     156# not be called in new code. 
    161157sub redirect { 
    162158    my ( $this, $session ) = @_; 
    163  
     159    my @p = $this->_prepareResponse($session); 
     160    my $url = 
     161      $session->getScriptUrl( 1, 'oops', $this->{web}, $this->{topic}, @p ); 
     162    $session->redirect( $url, 1 ); 
     163} 
     164 
     165=begin TML 
     166 
     167---++ ObjectMethod generate( $session ) 
     168 
     169Generate an error page for the exception. This will output the error page 
     170to the browser. The default HTTP Status for an Oops exception is 500. This 
     171can be overridden using the 'status => ' parameter to the constructor. 
     172 
     173=cut 
     174 
     175sub generate { 
     176    my ($this, $session ) = @_; 
     177 
     178    my @p = $this->_prepareResponse( $session ); 
     179    $session->{response}->status( $this->{status} || 500 ); 
     180    require Foswiki::UI::Oops; 
     181    Foswiki::UI::Oops::oops($session, $this->{web}, $this->{topic}, 
     182                            $session->{request}, 0); 
     183} 
     184 
     185sub _prepareResponse { 
     186    my ($this, $session ) = @_; 
    164187    my @p = (); 
    165188 
     
    170193    my $n = 1; 
    171194    push( @p, map { 'param' . ( $n++ ) => $_ } @{ $this->{params} } ); 
    172     my $url = 
    173       $session->getScriptUrl( 1, 'oops', $this->{web}, $this->{topic}, @p ); 
    174195    while ( my $p = shift(@p) ) { 
    175196        $session->{request}->param( -name => $p, -value => shift(@p) ); 
    176197    } 
    177     $session->redirect( $url, 1 ); 
     198    return @p; 
    178199} 
    179200 
Note: See TracChangeset for help on using the changeset viewer.