Skip to content

Commit 970b911

Browse files
committed
improve answerURL response handling
escape quote after encoding json
1 parent 964aca4 commit 970b911

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,24 +154,26 @@ 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+
174174
$answerJWTresponse = encode_json($answerJWTresponse);
175+
# this will become a string literal, so single-quote characters must be escaped
176+
$answerJWTresponse =~ s/'/\\'/g;
175177
$c->log->info("answerJWT response ".$answerJWTresponse);
176178

177179
$ww_return_hash->{renderedHTML} =~ s/JWTanswerURLstatus/$answerJWTresponse/g;

0 commit comments

Comments
 (0)