MT#59478 /api/ root error handling

* clear errors in Controller::API::Root::end so that they are
  not interfere with generated ones
* API::error(): add $c->stash->{is_api_error_response} = 1
  to track it in log_response()
* API::log_response(): distinguish and correctly correct errors
  for cases when is_api_response == 1 and also when there were
  $c->error('error') calls in the code, to log them correctly
  in both cases

Change-Id: Id922b8219832c1b99815d9d608309035b9b25cff
(cherry picked from commit 91f1dcf37e)
mr12.3.1
Kirill Solomko 1 year ago
parent 04e159bbb6
commit 48e88bacf4

@ -562,6 +562,7 @@ sub get_collection_properties {
sub end : Private {
my ($self, $c) = @_;
$c->clear_errors;
#$self->log_response($c);
return 1;
}

@ -356,6 +356,8 @@ sub error {
$c->error([$message, @errors]);
$c->stash->{is_api_error_response} = 1;
$c->response->content_type('application/json');
$c->response->status($code);
$c->response->body(JSON::to_json({ code => $code, message => $message })."\n");
@ -1062,7 +1064,9 @@ sub log_response {
my $rc = '';
my $errors = '';
if ($c->has_errors) {
$errors = join ', ', splice @{$c->error}, 1;
$errors = $c->stash->{is_api_error_response}
? join ', ', splice @{$c->error}, 1
: join ', ', @{$c->error};
$c->clear_errors;
}
my ($response_body, $params_data) = $self->filter_log_response(

Loading…
Cancel
Save