MT#62223 API unhandled internal errors cause 500 error

* unhandled internal errors (such as DBI error) are now properly
  returned as 500 Internal Server Error instead of 200 OK

Change-Id: Iabc80cd200c9091dd249bc90aa586d5d7b616b69
(cherry picked from commit cbc4e57d45)
(cherry picked from commit a743fcc1e3)
mr13.1.1
Kirill Solomko 2 months ago
parent 1f1abb8c59
commit 290673a04b

@ -1071,6 +1071,18 @@ sub log_response {
$errors = $c->stash->{is_api_error_response}
? join ', ', splice @{$c->error}, 1
: join ', ', @{$c->error};
# unhandled error message, should return 500 instead of 200
if ($c->response->status == 200) {
my $code = HTTP_INTERNAL_SERVER_ERROR;
$c->response->content_type('application/json');
$c->response->status($code);
$c->response->body(JSON::to_json({
code => $code,
message => "Internal Server Error" })."\n"
);
}
$c->clear_errors;
}
my ($response_body, $params_data) = $self->filter_log_response(

Loading…
Cancel
Save