From 6776f3aa1a1c0cca16fbab1ab3fa91445cfd5beb Mon Sep 17 00:00:00 2001 From: Kirill Solomko Date: Fri, 21 Feb 2025 16:07:35 +0100 Subject: [PATCH] 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 cbc4e57d4520cd5217fcd827ca9b53f7a931832d) (cherry picked from commit d0c8c42d280e520ea48150d1a3914e1752bc5b22) --- lib/NGCP/Panel/Role/API.pm | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/NGCP/Panel/Role/API.pm b/lib/NGCP/Panel/Role/API.pm index 865781105f..82b76aa6ae 100644 --- a/lib/NGCP/Panel/Role/API.pm +++ b/lib/NGCP/Panel/Role/API.pm @@ -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(