Skip to content

Instantly share code, notes, and snippets.

@renatocron
Created January 11, 2019 10:12
Show Gist options
  • Save renatocron/d458aa099bdc4107fda6a5539909a01f to your computer and use it in GitHub Desktop.
Save renatocron/d458aa099bdc4107fda6a5539909a01f to your computer and use it in GitHub Desktop.
package Queryexporter::Controller::Query::ViewRows;
use Mojo::Base 'Queryexporter::Controller';
use JSON;
sub preview {
my $c = shift;
my $user = $c->stash->{user_rs}->next or $c->user_not_found;
$c->subprocess(
sub {
my $subprocess = shift;
my $rows = eval { $c->stash('query')->fetchall_as_hash; die 'testing exception' };
if ($@) {
$rows = { exception => $@ };
}
return $rows;
},
sub {
my ( $c, $result ) = @_;
if ( ref $result eq 'HASH' && $result->{exception} ) {
$c->app->log->fatal( $c->app->dumper( $result->{exception} ) );
$c->render(
json => { error => "Internal server error" },
status => 500,
);
}
else {
$c->render(
json => {
rows => $result,
},
status => 200,
);
}
}
);
}
1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment