Created
January 11, 2019 10:12
-
-
Save renatocron/d458aa099bdc4107fda6a5539909a01f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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