From ddbce128e2bf3e0556ba860c9e486863bdf21f70 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 --- 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 fd28d67e7f6..3bf60c12311 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 948bed689bd..e0937e7a2a2 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.44.0