From b78128eec14184b503a7c57219f423cb49466f92 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 8 Feb 2023 11:59:11 +0100 Subject: [PATCH] Bug 32898: ERM - Improve fetch ... and fix cypress tests The main problem was that there were no more checkError call for fetchLocalTitleCount and the error was not displayed on the UI. This commit is doing several things: - Refactor fetch.js to call the same fetch method (myFetch) in order to deal with the error in a single place - Have a new myFetchTotal JS function to get the X-Total-Count header from the response and get the benefit of the previous refactoring - Rename fetchCountLocalPackages with fetchLocalPackagesCount to match fetchLocalTitleCount - Use fetchLocalPackagesCount on the Package list view - Use checkError from components using fetch directly. Ideally the could should be moved to fetch.js and myFetch should be used. - checkError get a new flag in parameter to ask for the response instead of the result (ie. the JSON of the response). That's useful when we need the response status or the headers - Make checkError throw a proper exception to stop propation. This modify the error we display on the UI, it's why we have the following changes in cypress tests: - "Something went wrong: Internal Server Error" + "Something went wrong: Error: Internal Server Error" That's not ideal, we should have our own JS exception to avoid that "Error" (coming from the toString call on the error) --- .../vue/components/ERM/AgreementsFormAdd.vue | 3 +- .../ERM/AgreementsFormConfirmDelete.vue | 3 +- .../ERM/EHoldingsEBSCOPackagesList.vue | 4 +- .../ERM/EHoldingsLocalPackagesFormAdd.vue | 15 +- ...HoldingsLocalPackagesFormConfirmDelete.vue | 3 +- .../ERM/EHoldingsLocalPackagesList.vue | 15 +- .../ERM/EHoldingsLocalTitlesFormAdd.vue | 9 +- .../EHoldingsLocalTitlesFormConfirmDelete.vue | 3 +- .../ERM/EHoldingsLocalTitlesList.vue | 8 +- .../js/vue/components/ERM/LicensesFormAdd.vue | 3 +- .../ERM/LicensesFormConfirmDelete.vue | 3 +- koha-tmpl/intranet-tmpl/prog/js/vue/fetch.js | 246 +++++------------- t/cypress/integration/Agreements_spec.ts | 6 +- t/cypress/integration/Licenses_spec.ts | 6 +- t/cypress/integration/Packages_spec.ts | 15 +- t/cypress/integration/Titles_spec.ts | 15 +- 16 files changed, 138 insertions(+), 219 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementsFormAdd.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementsFormAdd.vue index b21340f562a..bcfd66111d1 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementsFormAdd.vue +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementsFormAdd.vue @@ -190,7 +190,7 @@ import AgreementLicenses from "./AgreementLicenses.vue" import AgreementRelationships from "./AgreementRelationships.vue" import Documents from "./Documents.vue" import { setMessage, setError, setWarning } from "../../messages" -import { fetchAgreement } from "../../fetch" +import { fetchAgreement, checkError } from "../../fetch" import { storeToRefs } from "pinia" export default { @@ -384,6 +384,7 @@ export default { } fetch(apiUrl, options) + .then(response => checkError(response, 1)) .then(response => { if (response.status == 200) { this.$router.push("/cgi-bin/koha/erm/agreements") diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementsFormConfirmDelete.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementsFormConfirmDelete.vue index 5a98d042046..8c2fc90d165 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementsFormConfirmDelete.vue +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementsFormConfirmDelete.vue @@ -36,7 +36,7 @@