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 <kyle@bywatersolutions.com>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
[OK] prove t/db_dependent/api/v1/items.t t/db_dependent/api/v1/unhandled_exceptions.t
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
This commit is contained in:
Tomás Cohen Arazi 2024-03-27 12:29:31 +00:00 committed by Katrin Fischer
parent 3ed4e096b0
commit e518e0be2c
Signed by: kfischer
GPG key ID: 0EF6E2C03357A834
2 changed files with 5 additions and 12 deletions

View file

@ -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',
}
);

View file

@ -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($_);
}
};