Commit 06346c4c authored by Hubert depesz Lubaczewski's avatar Hubert depesz Lubaczewski
Browse files

Better way to display errors

parent fb64ca88
......@@ -19,6 +19,7 @@ sub startup {
# Normal route to controller
$r->get( '/' )->to( 'main#home' )->name( 'home' );
$r->get( '/error' )->to( 'main#error' )->name( 'error' );
$r->get( '/show' )->to( 'main#show' )->name( 'show' );
$r->get( '/metainfo' )->to( 'main#metainfo' )->name( 'metainfo' );
}
......
......@@ -16,17 +16,34 @@ sub home {
sub show_validate {
my $self = shift;
my $from = $self->param( 'from' );
my $to = $self->param( 'to' );
my $from = $self->param( 'from' ) // '';
my $to = $self->param( 'to' ) // '';
# Validate that the versions given as from/to are ok
return $self->redirect_to( 'home' ) unless $from;
return $self->redirect_to( 'home' ) unless $from =~ m{\A\d+(\.\d+){0,2}\z};
return $self->redirect_to( 'home' ) unless $to;
return $self->redirect_to( 'home' ) unless $to =~ m{\A\d+(\.\d+){0,2}\z};
return $self->redirect_to( 'home' ) unless $self->db->valid_release( $from );
return $self->redirect_to( 'home' ) unless $self->db->valid_release( $to );
return $self->redirect_to( 'home' ) unless $from ne $to;
my @bad_versions = ();
unless (
( $from =~ m{\A\d+(\.\d+){0,2}\z} ) &&
( $self->db->valid_release( $from ) )
) {
push @bad_versions, $from;
}
unless (
( $to =~ m{\A\d+(\.\d+){0,2}\z} ) &&
( $self->db->valid_release( $to ) )
) {
push @bad_versions, $to;
}
if ( 0 < scalar @bad_versions ) {
$self->flash( 'msg' => 'bad_versions' );
$self->flash( 'vers' => \@bad_versions );
return $self->redirect_to( 'error' );
}
if ( $from eq $to ) {
$self->flash( 'msg' => 'same_version' );
$self->flash( 'ver' => $from );
return $self->redirect_to( 'error' );
}
# Check if we don't need to swap from/to
my $o_from = Pg::Version->new( $from );
......
......@@ -228,3 +228,17 @@ p {
padding: 0;
padding-left: 1em;
}
#error {
color: #fc0;
border: 1px solid #f40;
margin: 1em 3em 0em 3em;
padding: 1em;
background: #400;
}
#error h1 {
padding: 0;
margin: 0;
}
#error span {
color: #ff0;
}
% layout 'default';
<div id="error">
% if ( flash('msg') eq 'same_version' ) {
<h1>You tried to display diff from the same version to the same version (<span><%= flash('ver') %></span>)</h2>
% } elsif ( flash('msg') eq 'bad_versions' ) {
% if ( 1 == scalar @{ flash('vers') } ) {
<h1>Given version (<span><%= flash('vers')->[0] %></span>) is incorrect.</h1>
% } else {
<h1>Given versions (<span><%= join ', ', @{ flash('vers') } %></span>) are incorrect.</h1>
% }
% } else {
<h1>Something bad happened, but not sure what, sorry.</h2>
% }
</div>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment