From 6e0e84bc9efee37da5daf1eae5b50f651608a7af Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Fri, 1 Mar 2024 07:58:00 +0000 Subject: [PATCH] Bug 36100: (QA follow-up) Move 400 to 409 Duplicate exceptions tend to generate a 409 in our REST API. Signed-off-by: Marcel de Rooy Signed-off-by: Katrin Fischer (cherry picked from commit 3e164d200acd683119225d4ebd01ad0334f563fb) Signed-off-by: Fridolin Somers --- Koha/REST/V1/Bookings.pm | 2 +- api/v1/swagger/paths/bookings.yaml | 4 ++++ t/db_dependent/api/v1/bookings.t | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Koha/REST/V1/Bookings.pm b/Koha/REST/V1/Bookings.pm index 0e355f23dd..2d1bb25ad8 100644 --- a/Koha/REST/V1/Bookings.pm +++ b/Koha/REST/V1/Bookings.pm @@ -93,7 +93,7 @@ sub add { ); } elsif ( blessed $_ and $_->isa('Koha::Exceptions::Object::DuplicateID') ) { return $c->render( - status => 400, + status => 409, openapi => { error => "Duplicate booking_id", } diff --git a/api/v1/swagger/paths/bookings.yaml b/api/v1/swagger/paths/bookings.yaml index f1dcb9f9be..f7bb0b8804 100644 --- a/api/v1/swagger/paths/bookings.yaml +++ b/api/v1/swagger/paths/bookings.yaml @@ -102,6 +102,10 @@ description: Access forbidden schema: $ref: ../swagger.yaml#/definitions/error + 409: + description: Conflict + schema: + $ref: ../swagger.yaml#/definitions/error 500: description: Internal error schema: diff --git a/t/db_dependent/api/v1/bookings.t b/t/db_dependent/api/v1/bookings.t index 14a4396f46..8ede614153 100755 --- a/t/db_dependent/api/v1/bookings.t +++ b/t/db_dependent/api/v1/bookings.t @@ -262,7 +262,7 @@ subtest 'add() tests' => sub { # Authorized attempt to create with existing id $booking->{booking_id} = $booking_id; - $t->post_ok( "//$userid:$password@/api/v1/bookings" => json => $booking )->status_is(400) + $t->post_ok( "//$userid:$password@/api/v1/bookings" => json => $booking )->status_is(409) ->json_is( "/error" => "Duplicate booking_id" ); # TODO: Test bookings clashes -- 2.39.5