diff options
author | Matthew Somerville <matthew@mysociety.org> | 2020-04-27 07:29:48 +0100 |
---|---|---|
committer | Matthew Somerville <matthew@mysociety.org> | 2020-04-28 13:29:39 +0100 |
commit | f76f140d7dedbb9009e40e216da1f6d337f440e0 (patch) | |
tree | 74e8858f6db6243333c0711f4fdd304d6b270278 /perllib | |
parent | 4edf5a8a9b46311b3889a5382dfd05f7caf1d792 (diff) |
Error page when submitting /import with web param.
If the web param is used, show an error web page rather than the normal
plain text output. Also do the normal remember/show uploaded photos
feature, and hide the inputs better if unneeded.
Diffstat (limited to 'perllib')
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report/New.pm | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm index 516752b89..69d20171a 100644 --- a/perllib/FixMyStreet/App/Controller/Report/New.pm +++ b/perllib/FixMyStreet/App/Controller/Report/New.pm @@ -358,8 +358,7 @@ sub report_import : Path('/import') { # If this is not a POST then just print out instructions for using page return unless $c->req->method eq 'POST'; - # anything else we return is plain text - $c->res->content_type('text/plain; charset=utf-8'); + my $format = $c->get_param('web') ? 'web' : 'text'; my %input = map { $_ => $c->get_param($_) || '' } ( @@ -412,8 +411,14 @@ sub report_import : Path('/import') { # if we have errors then we should bail out if (@errors) { - my $body = join '', map { "ERROR:$_\n" } @errors; - $c->res->body($body); + if ($format eq 'web') { + $c->stash->{input} = \%input; + $c->stash->{errors} = \@errors; + } else { + my $body = join '', map { "ERROR:$_\n" } @errors; + $c->res->content_type('text/plain; charset=utf-8'); + $c->res->body($body); + } return; } @@ -469,13 +474,13 @@ sub report_import : Path('/import') { $c->send_email( 'partial.txt', { to => $report->user->email, } ); - if ( $c->get_param('web') ) { - $c->res->content_type('text/html; charset=utf-8'); + if ($format eq 'web') { $c->stash->{template} = 'email_sent.html'; $c->stash->{email_type} = 'problem'; - return 1; + } else { + $c->res->content_type('text/plain; charset=utf-8'); + $c->res->body('SUCCESS'); } - $c->res->body('SUCCESS'); return 1; } |