From cc82d3569748bf45f67b9734839e41925a5483cc Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Mon, 27 Dec 2021 08:27:24 -0300 Subject: [PATCH] Bug 28020: Add error_code to error responses This patch adds the *error_code* attribute to the error response definition. This way it can be added when returning an error. I also made a sample usage of it on the generic unhandled_exception helper, which the unit tests on this patchset expect. To test: 1. Apply the unit tests patch 2. Run: $ kshell k$ prove t/db_dependent/api/v1/unhandled_exceptions.t => FAIL: The unhandled_exception() helper doesn't return an error_code in the response payload. 3. Apply this patch 4. Repeat 2 => SUCCESS: Tests pass! Signed-off-by: Tomas Cohen Arazi Signed-off-by: Andrew Fuerste-Henry Signed-off-by: Jonathan Druart --- Koha/REST/Plugin/Exceptions.pm | 6 +++--- api/v1/swagger/definitions/error.yaml | 3 +++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Koha/REST/Plugin/Exceptions.pm b/Koha/REST/Plugin/Exceptions.pm index e9be043aa2b..b0697115964 100644 --- a/Koha/REST/Plugin/Exceptions.pm +++ b/Koha/REST/Plugin/Exceptions.pm @@ -76,11 +76,11 @@ sub register { status => 500, openapi => { error => - "Something went wrong, check Koha logs for details." + "Something went wrong, check Koha logs for details.", + error_code => 'internal_server_error', } ); - } - + } ); } diff --git a/api/v1/swagger/definitions/error.yaml b/api/v1/swagger/definitions/error.yaml index 8576374a8b5..8f52da4c137 100644 --- a/api/v1/swagger/definitions/error.yaml +++ b/api/v1/swagger/definitions/error.yaml @@ -4,4 +4,7 @@ properties: error: description: Error message type: string + error_code: + description: Error code + type: string additionalProperties: true -- 2.25.1