From 0705360fc8dd81f1c09e92859a200bb28c10c643 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Wed, 27 Mar 2024 12:29:31 +0000 Subject: [PATCH] Bug 36421: Make sure pre-controller errors are correctly logged If something explodes in Koha::REST::V1::Auth chances are that no logging will happen. This patch makes sure they are! To test: 1. Make sure you do NOT have 36420 on your tree 2. Make sure you are looking at the logs: $ ktd --shell k$ koha-plack --restart kohadev; tail -f /var/log/koha/kohadev/*.log 3. Use Postman or similar for hitting some known endpoint. Use the user's cardnumber instead of the userid. On a default KTD launch, the generated user's cardnumber is '42'. GET /patrons => FAIL: You get a 500 error (expected, fixed on 36420) but no useful logging found. 4. Apply this patch 5. Ctrl+c on the logs and re-run the command 6. Repeat 3 => SUCCESS: You get a 500, but you also get the exception information logged! 7. Sign off :-D Signed-off-by: Kyle M Hall Signed-off-by: Marcel de Rooy [OK] prove t/db_dependent/api/v1/items.t t/db_dependent/api/v1/unhandled_exceptions.t Signed-off-by: Katrin Fischer (cherry picked from commit e518e0be2c97782997037383223e57ce2e196df4) Signed-off-by: Fridolin Somers --- Koha/REST/Plugin/Exceptions.pm | 7 +++---- Koha/REST/V1/Auth.pm | 10 ++-------- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/Koha/REST/Plugin/Exceptions.pm b/Koha/REST/Plugin/Exceptions.pm index fd28d67e7f..3bf60c1231 100644 --- a/Koha/REST/Plugin/Exceptions.pm +++ b/Koha/REST/Plugin/Exceptions.pm @@ -71,10 +71,9 @@ sub register { $c->app->log->error( "$message" ); $c->render( - status => 500, - openapi => { - error => - "Something went wrong, check Koha logs for details.", + status => 500, + json => { + error => "Something went wrong, check Koha logs for details.", error_code => 'internal_server_error', } ); diff --git a/Koha/REST/V1/Auth.pm b/Koha/REST/V1/Auth.pm index 948bed689b..e0937e7a2a 100644 --- a/Koha/REST/V1/Auth.pm +++ b/Koha/REST/V1/Auth.pm @@ -95,10 +95,7 @@ sub under { } catch { unless (blessed($_)) { - return $c->render( - status => 500, - json => { error => 'Something went wrong, check the logs.' } - ); + $c->unhandled_exception($_); } if ($_->isa('Koha::Exceptions::UnderMaintenance')) { return $c->render(status => 503, json => { error => $_->error }); @@ -128,10 +125,7 @@ sub under { return $c->render(status => 500, json => { error => $_->error }); } else { - return $c->render( - status => 500, - json => { error => 'Something went wrong, check the logs.' } - ); + $c->unhandled_exception($_); } }; -- 2.39.5