diff --git a/Koha/REST/V1/Biblios.pm b/Koha/REST/V1/Biblios.pm index 0b5db5dc9a..794a968af8 100644 --- a/Koha/REST/V1/Biblios.pm +++ b/Koha/REST/V1/Biblios.pm @@ -704,9 +704,22 @@ sub add { ) if $duplicatebiblionumber; } - 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 } ); diff --git a/api/v1/swagger/paths/biblios.yaml b/api/v1/swagger/paths/biblios.yaml index 6502a4f67d..89252ce9f1 100644 --- a/api/v1/swagger/paths/biblios.yaml +++ b/api/v1/swagger/paths/biblios.yaml @@ -29,7 +29,10 @@ "200": description: A biblio "400": - description: Bad request + description: | + Bad request. Possible `error_code` attribute values: + + * `record_creation_failed`: An error occurred during record creation. The cause could not be determined. schema: $ref: "../swagger.yaml#/definitions/error" "401":