Bugzilla – Attachment 176796 Details for
Bug 38926
POST /biblios returns 200 even if AddBiblio fails
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 38926: Make POST /biblios return 400 if AddBiblio fails
Bug-38926-Make-POST-biblios-return-400-if-AddBibli.patch (text/plain), 1.97 KB, created by
Tomás Cohen Arazi (tcohen)
on 2025-01-20 13:10:46 UTC
(
hide
)
Description:
Bug 38926: Make POST /biblios return 400 if AddBiblio fails
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2025-01-20 13:10:46 UTC
Size:
1.97 KB
patch
obsolete
>From 4234a2ea7f78d8db590336ccc07ce201cd97d79e Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Mon, 20 Jan 2025 10:06:22 -0300 >Subject: [PATCH] Bug 38926: Make POST /biblios return 400 if AddBiblio fails > >We don't have proper exceptions in the `C4::Biblio::AddBiblio` method, >but we at least know `$biblio_id` will be `undef` in the even of an >error processing the call. > >This patch makes the controller handle this situation so (at least) it >is obvious that something bad happened. > >To test: >1. Apply the regression tests patch >2. Run: > $ ktd --shell > k$ prove t/db_dependent/api/v1/biblios.t >=> FAIL: Tests fail! The endpoint returns 200 even on error! >3. Apply this patch >4. Repeat 2 >=> SUCCESS: Tests pass! The endpoint returns a 400 with a reasonable >message! >5. Sign off :-D >--- > Koha/REST/V1/Biblios.pm | 17 +++++++++++++++-- > 1 file changed, 15 insertions(+), 2 deletions(-) > >diff --git a/Koha/REST/V1/Biblios.pm b/Koha/REST/V1/Biblios.pm >index 035d215c52f..010f96e7e96 100644 >--- a/Koha/REST/V1/Biblios.pm >+++ b/Koha/REST/V1/Biblios.pm >@@ -703,9 +703,22 @@ sub add { > } > ) unless !$duplicatebiblionumber || $confirm_not_duplicate; > >- my ( $biblio_id ) = AddBiblio( $record, $frameworkcode, { record_source_id => $record_source_id } ); >+ my ($biblio_id) = C4::Biblio::AddBiblio( $record, $frameworkcode, { record_source_id => $record_source_id } ); > >- $c->render( >+ if ( !$biblio_id ) { >+ >+ # FIXME: AddBiblio wraps everything inside a transaction and a try/catch block >+ # this will need a tweak if this behavior changes >+ return $c->render( >+ status => 400, >+ openapi => { >+ error => 'Error creating record', >+ error_code => 'record_creation_failed', >+ }, >+ ); >+ } >+ >+ return $c->render( > status => 200, > openapi => { id => $biblio_id } > ); >-- >2.48.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 38926
:
176795
|
176796
|
176835
|
176847
|
176848
|
176890
|
176891