Added nicer explosions via try::tiny
This commit is contained in:
parent
d1cd30928e
commit
afc635fdb4
6 changed files with 27 additions and 33 deletions
|
@ -1,7 +1,7 @@
|
|||
package Pear::LocalLoop::Controller::Admin::ImportFrom;
|
||||
use Mojo::Base 'Mojolicious::Controller';
|
||||
use Moo;
|
||||
use Devel::Dwarn;
|
||||
use Try::Tiny;
|
||||
|
||||
use Pear::LocalLoop::Import::LCCCsv::Suppliers;
|
||||
use Pear::LocalLoop::Import::LCCCsv::Transactions;
|
||||
|
@ -47,19 +47,22 @@ sub post_transactions {
|
|||
$c->flash( error => "CSV file size is too large" );
|
||||
return $c->redirect_to( '/admin/import_from' );
|
||||
}
|
||||
my $csv_import = Pear::LocalLoop::Import::LCCCsv::Transactions->new(
|
||||
csv_string => $c->param('transactions_csv')->slurp,
|
||||
schema => $c->app->schema
|
||||
)->import_csv;
|
||||
|
||||
if ($csv_import->csv_error) {
|
||||
$c->flash( error => $csv_import->csv_error );
|
||||
my $csv_error;
|
||||
try {
|
||||
Pear::LocalLoop::Import::LCCCsv::Transactions->new(
|
||||
csv_string => $c->param('transactions_csv')->slurp,
|
||||
schema => $c->app->schema
|
||||
)->import_csv;
|
||||
} catch {
|
||||
$csv_error = $_;
|
||||
};
|
||||
if ( $csv_error ) {
|
||||
$c->flash( error => $csv_error );
|
||||
return $c->redirect_to( '/admin/import_from' );
|
||||
} else {
|
||||
$c->flash( success => "CSV imported" );
|
||||
return $c->redirect_to( '/admin/import_from' );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
Reference in a new issue