[Bug 42595] New: REST API: Holds controller renders bare strings instead of error objects
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42595 Bug ID: 42595 Summary: REST API: Holds controller renders bare strings instead of error objects Initiative type: --- Sponsorship --- status: Product: Koha Version: Main Hardware: All OS: All Status: NEW Severity: major Priority: P5 - low Component: REST API Assignee: koha-bugs@lists.koha-community.org Reporter: tomascohen@gmail.com QA Contact: testopia@bugs.koha-community.org CC: tomascohen@gmail.com The Holds controller (Koha::REST::V1::Holds) has three places where error responses are rendered as bare strings instead of the expected error object (`{ error => "..." }`). This causes Mojolicious::Plugin::OpenAPI response validation to fail with a 500: {"errors":[{"message":"Expected object - got string.","path":"/body"}],"status":500} The error definition in the spec has always been `type: object`, so these are latent bugs that surface when the specific code paths are hit. Affected lines in Koha/REST/V1/Holds.pm: 1. Line 134: `openapi => "Bibliographic record not found"` (status 400) - Triggered when biblio_id doesn't exist 2. Line 222: `openapi => 'Error placing the hold...'` (status 500) - Triggered on unhandled exceptions during hold placement 3. Line 242: `openapi => ...to_api_mapping->{$broken_fk} . ' not found.'` (status 404) - Triggered on foreign key violations All three should be: `openapi => { error => $message }` Found in production (25.11.02) when Aspen Discovery attempted to place a hold on a deleted biblio (biblio_id that no longer exists in the database). -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42595 Tomás Cohen Arazi (tcohen) <tomascohen@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Assignee|koha-bugs@lists.koha-commun |tomascohen@gmail.com |ity.org | -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42595 Tomás Cohen Arazi (tcohen) <tomascohen@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |Needs Signoff Patch complexity|--- |Small patch -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42595 --- Comment #1 from Tomás Cohen Arazi (tcohen) <tomascohen@gmail.com> --- Created attachment 199111 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=199111&action=edit Bug 42595: Add render_error helper and fix bare string responses This patch adds a render_error helper to Koha::REST::Plugin::Responses that enforces the error object contract (status + error_code mandatory, error message optional). It then uses the helper to fix the three bare string error responses in Koha::REST::V1::Holds that caused OpenAPI response validation to produce 500 errors. Test plan: 1. Apply the regression test patch (previous commit) 2. Run: $ ktd --shell k$ prove xt/api.t => FAIL: Detects bare strings in Holds.pm 3. Apply this patch 4. Run: k$ prove xt/api.t t/db_dependent/api/v1/holds.t t/db_dependent/api/v1/responses.t => SUCCESS: Tests pass! 5. Sign off :-D Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42595 Tomás Cohen Arazi (tcohen) <tomascohen@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Summary|REST API: Holds controller |Holds controller renders |renders bare strings |bare strings instead of |instead of error objects |error objects -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42595 David Nind <david@davidnind.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |david@davidnind.com --- Comment #2 from David Nind <david@davidnind.com> --- For step 1, should there be another patch with this bug? With just the one patch on the bug applied, the tests pass. -- You are receiving this mail because: You are watching all bug changes.
participants (1)
-
bugzilla-daemon@bugs.koha-community.org