MT#62223 improve error response handling when log_response is off

* log_response: 0 is reworked, it now always logs the response but
  in case if it's off the body is not logged.
* adjust error logging, the error in the body is correctly
  logged in the response even if log_response: 0

Change-Id: I6dfddeccffb5464b830133235bf63c5e82ae6073
(cherry picked from commit e8f41aba50)
mr13.1
Kirill Solomko 2 months ago
parent a743fcc1e3
commit 947fe43371

@ -1065,9 +1065,11 @@ sub log_response {
$c->forward(qw(Controller::Root render));
$c->response->content_type('')
if $c->response->content_type =~ qr'text/html'; # stupid RenderView getting in the way
my $rc = '';
my $errors = '';
my $has_errors = 0;
if ($c->has_errors) {
$has_errors = 1;
$errors = $c->stash->{is_api_error_response}
? join ', ', splice @{$c->error}, 1
: join ', ', @{$c->error};
@ -1083,19 +1085,31 @@ sub log_response {
);
}
# to avoid html content response
$c->clear_errors;
}
my ($response_body, $params_data) = $self->filter_log_response(
my ($response_body, $params_data) =
(
($has_errors || $self->get_config('log_response'))
? $c->response->body
: undef,
$c->request->parameters
);
my ($filtered_response_body, $filtered_params_data) =
$self->filter_log_response(
$c,
$c->response->body,
$c->request->parameters,
$response_body,
$params_data
);
NGCP::Panel::Utils::Message::info(
c => $c,
type => 'api_response',
desc => $c->qs($response_body),
desc => $c->qs($filtered_response_body),
log => $c->qs($errors // ''),
data => $params_data,
data => $filtered_params_data,
);
}

@ -33,9 +33,7 @@ sub end :Private {
}
}
if ($self->get_config('log_response')) {
$self->log_response($c);
}
$self->log_response($c);
return 1;
}

@ -38,9 +38,7 @@ sub end :Private {
}
}
if ($self->get_config('log_response')) {
$self->log_response($c);
}
$self->log_response($c);
return 1;
}

Loading…
Cancel
Save