aboutsummaryrefslogtreecommitdiff
path: root/lib/MasterWebInterface/Handler/ErrorPages.pm
blob: 1678acce80a5482da26f1ca08692acc8f4e458fb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package MasterWebInterface::Handler::ErrorPages;
use strict;
use TUWF ':html';

# handle 404 and 500
TUWF::set(
    error_404_handler => \&handle404,
    error_500_handler => \&handle500,
);

TUWF::register(
    qr{500} => sub {die "Process died on purpose, but with a lot of text to test if the whole error is correctly displayed on the screen when debug information is enabled in the website configuration. "},
);

#
# 404 page or json status
sub handle404 
{
    my $self = shift;

    # json error status separately
    if ( $self->reqPath() =~ m/^\/json/ig)
    {
        # response as json data
        $self->resHeader("Access-Control-Allow-Origin", "*");
        $self->resJSON({
            error => 1, 
            in => "url_format"
        });
        return;
    }
    
    $self->resStatus(404);
    $self->htmlHeader(title => '404 - Not Found');
    $self->htmlFilterBox(title => "Servers", action => "/s", sel => 's', fq => '');
    
    div class => "mainbox warning";
        div class => "header";
            h1 'Page not found';
            p "Error 404: the page could not be found.";
        end;
        
        div class => "description";
            p;
                txt 'It seems the page you were looking for does not exist,';
                br;
                txt 'perhaps our search function may yield results?';
            end;
        end;
    end;
    $self->htmlFooter;
}

#
# 500 page or json status
sub handle500 
{
    my($self, $error) = @_;
    
    # json error status separately
    if ( $self->reqPath() =~ m/^\/json/ig)
    {
        # response as json data
        $self->resHeader("Access-Control-Allow-Origin", "*");
        $self->resJSON({
            error => 1, 
            in => "internal_error", 
            internal => ( $self->debug ? $error : () )
        });
        return;
    }
    
    $self->resStatus(500);
    $self->htmlHeader(title => '500 - Internal Server Error');
    $self->htmlFilterBox(title => "Servers", action => "/s", sel => 's', fq => '');
    
    div class => "mainbox warning";
        div class => "header";
            h1 'Internal Server Error';
            p "Error 500: loading this page caused an internal error.";
        end;
        
        div class => "description";
            p;
                txt 'Something went wrong on our side. The problem was logged ';
                br;
                txt 'and will be fixed shortly. Please try again later.';
            end;
        
            if ($self->debug) 
            {
                p $error;
            }
        end;
    end;
    $self->htmlFooter;
}

1;