diff --git a/lib/NGCP/Panel/Role/API.pm b/lib/NGCP/Panel/Role/API.pm index 82b76aa6ae..5f499be400 100644 --- a/lib/NGCP/Panel/Role/API.pm +++ b/lib/NGCP/Panel/Role/API.pm @@ -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, ); } diff --git a/lib/NGCP/Panel/Role/Entities.pm b/lib/NGCP/Panel/Role/Entities.pm index ae98833eb1..28baa941f6 100644 --- a/lib/NGCP/Panel/Role/Entities.pm +++ b/lib/NGCP/Panel/Role/Entities.pm @@ -33,9 +33,7 @@ sub end :Private { } } - if ($self->get_config('log_response')) { - $self->log_response($c); - } + $self->log_response($c); return 1; } diff --git a/lib/NGCP/Panel/Role/EntitiesItem.pm b/lib/NGCP/Panel/Role/EntitiesItem.pm index 93875e0969..9e4ba3a9b6 100644 --- a/lib/NGCP/Panel/Role/EntitiesItem.pm +++ b/lib/NGCP/Panel/Role/EntitiesItem.pm @@ -38,9 +38,7 @@ sub end :Private { } } - if ($self->get_config('log_response')) { - $self->log_response($c); - } + $self->log_response($c); return 1; }