Skip to content

Commit e3e21d8

Browse files
committed
improve answerURL response handling
1 parent 964aca4 commit e3e21d8

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

lib/RenderApp/Controller/Render.pm

+12-10
Original file line numberDiff line numberDiff line change
@@ -154,23 +154,25 @@ async sub problem {
154154
my $response = shift->result;
155155

156156
$answerJWTresponse->{status} = int($response->code);
157-
if ($response->is_success) {
157+
# answerURL responses are expected to be JSON
158+
if ($response->json) {
159+
# munge data with default response object
160+
$answerJWTresponse = { %$answerJWTresponse, %{$response->json} };
161+
} else {
162+
# otherwise throw the whole body as the message
158163
$answerJWTresponse->{message} = $response->body;
159164
}
160-
elsif ($response->is_error) {
161-
$answerJWTresponse->{message} = '[' . $c->logID . '] ' . $response->message;
162-
}
163-
164-
$answerJWTresponse->{message} =~ s/"/\\"/g;
165-
$answerJWTresponse->{message} =~ s/'/\'/g;
166165
})->
167166
catch(sub {
168-
my $response = shift;
169-
$c->log->error($response);
167+
my $err = shift;
168+
$c->log->error($err);
170169

171170
$answerJWTresponse->{status} = 500;
172-
$answerJWTresponse->{message} = '[' . $c->logID . '] ' . $response;
171+
$answerJWTresponse->{message} = '[' . $c->logID . '] ' . $err;
173172
});
173+
174+
$answerJWTresponse->{message} =~ s/"/\\"/g;
175+
$answerJWTresponse->{message} =~ s/'/\\'/g;
174176
$answerJWTresponse = encode_json($answerJWTresponse);
175177
$c->log->info("answerJWT response ".$answerJWTresponse);
176178

0 commit comments

Comments
 (0)