Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Sign in / Register
Toggle navigation
Open sidebar
Hubert Lubaczewski
pgVersions
Commits
06346c4c
Commit
06346c4c
authored
Feb 26, 2021
by
Hubert depesz Lubaczewski
Browse files
Better way to display errors
parent
fb64ca88
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
57 additions
and
9 deletions
+57
-9
lib/PgWhyUpgrade.pm
lib/PgWhyUpgrade.pm
+1
-0
lib/PgWhyUpgrade/Controller/Main.pm
lib/PgWhyUpgrade/Controller/Main.pm
+26
-9
public/css/style.css
public/css/style.css
+14
-0
templates/main/error.html.ep
templates/main/error.html.ep
+16
-0
No files found.
lib/PgWhyUpgrade.pm
View file @
06346c4c
...
...
@@ -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
'
);
}
...
...
lib/PgWhyUpgrade/Controller/Main.pm
View file @
06346c4c
...
...
@@ -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
);
...
...
public/css/style.css
View file @
06346c4c
...
...
@@ -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
;
}
templates/main/error.html.ep
0 → 100644
View file @
06346c4c
% 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>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment