Bugzilla – Attachment 147064 Details for
Bug 32939
Have generic fetch functions in vue modules
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 32939: Uniformize api calls
Bug-32939-Uniformize-api-calls.patch (text/plain), 8.87 KB, created by
Matt Blenkinsop
on 2023-02-21 16:15:30 UTC
(
hide
)
Description:
Bug 32939: Uniformize api calls
Filename:
MIME Type:
Creator:
Matt Blenkinsop
Created:
2023-02-21 16:15:30 UTC
Size:
8.87 KB
patch
obsolete
>From 68732a6643ff7aa46c02a55e503c47e01a5b295f Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Wed, 15 Feb 2023 11:38:08 +0100 >Subject: [PATCH] Bug 32939: Uniformize api calls > >We want to make the call easier and without less errors possible. >Here, no need to async keyword, try-catch, etc. >Only call the method and use the common then with the 2 success and >error Promise arguments. > >We will certainly want to add later a parameter to prevent the display >of the error in fetchJSON, in case the failure does not require a message >for the end user. > >Signed-off-by: Matt Blenkinsop <matt.blenkinsop@ptfs-europe.com> >--- > .../vue/components/ERM/AgreementsFormAdd.vue | 44 +++++++++---------- > .../ERM/AgreementsFormConfirmDelete.vue | 29 +++++------- > .../js/vue/components/ERM/AgreementsList.vue | 10 +++-- > .../js/vue/components/ERM/AgreementsShow.vue | 12 +++-- > .../prog/js/vue/fetch/http-client.js | 15 ++++--- > 5 files changed, 55 insertions(+), 55 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 5c0932387eb..fefe29957d8 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 >@@ -254,14 +254,13 @@ export default { > methods: { > async getAgreement(agreement_id) { > const client = APIClient.erm >- try { >- await client.agreements.get(agreement_id).then(data => { >+ client.agreements.get(agreement_id).then( >+ data => { > this.agreement = data > this.initialized = true >- }) >- } catch (err) { >- setError(err.message || err.statusText) >- } >+ }, >+ error => {} >+ ) > }, > checkForm(agreement) { > let errors = [] >@@ -376,22 +375,23 @@ export default { > delete agreement.agreement_packages > > const client = APIClient.erm >- ;(async () => { >- try { >- if (agreement_id) { >- await client.agreements >- .update(agreement, agreement_id) >- .then(setMessage(this.$__("Agreement updated"))) >- } else { >- await client.agreements >- .create(agreement) >- .then(setMessage(this.$__("Agreement created"))) >- } >- this.$router.push("/cgi-bin/koha/erm/agreements") >- } catch (err) { >- setError(err.message || err.statusText) >- } >- })() >+ if (agreement_id) { >+ client.agreements.update(agreement, agreement_id).then( >+ success => { >+ setMessage(this.$__("Agreement updated")) >+ this.$router.push("/cgi-bin/koha/erm/agreements") >+ }, >+ error => {} >+ ) >+ } else { >+ client.agreements.create(agreement).then( >+ success => { >+ setMessage(this.$__("Agreement created")) >+ this.$router.push("/cgi-bin/koha/erm/agreements") >+ }, >+ error => {} >+ ) >+ } > }, > onStatusChanged(e) { > if (e.authorised_value != "closed") { >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 257a5de33f2..6fd85377913 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 >@@ -37,7 +37,7 @@ > > <script> > import { APIClient } from "../../fetch/api-client.js" >-import { setMessage, setError } from "../../messages" >+import { setMessage } from "../../messages" > > export default { > data() { >@@ -54,29 +54,22 @@ export default { > methods: { > async getAgreement(agreement_id) { > const client = APIClient.erm >- try { >- await client.agreements.get(agreement_id).then(data => { >- this.agreement = data >- this.initialized = true >- }) >- } catch (err) { >- setError(err.message || err.statusText) >- } >+ client.agreements.get(agreement_id).then(data => { >+ this.agreement = data >+ this.initialized = true >+ }) > }, > onSubmit(e) { > e.preventDefault() > > const client = APIClient.erm >- ;(async () => { >- try { >- await client.agreements >- .delete(this.agreement.agreement_id) >- .then(setMessage(this.$__("Agreement deleted"))) >+ client.agreements.delete(this.agreement.agreement_id).then( >+ success => { >+ setMessage(this.$__("Agreement deleted")) > this.$router.push("/cgi-bin/koha/erm/agreements") >- } catch (err) { >- setError(err) >- } >- })() >+ }, >+ error => {} >+ ) > }, > }, > name: "AgreementsFormConfirmDelete", >diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementsList.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementsList.vue >index 1684c245917..f58b6814e25 100644 >--- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementsList.vue >+++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementsList.vue >@@ -94,9 +94,13 @@ export default { > methods: { > async getAgreements() { > const client = APIClient.erm >- const agreements = await client.agreements.getAll() >- this.agreements = agreements >- this.initialized = true >+ await client.agreements.getAll().then( >+ data => { >+ this.agreements = data >+ this.initialized = true >+ }, >+ error => {} >+ ) > }, > show_agreement: function (agreement_id) { > this.$router.push("/cgi-bin/koha/erm/agreements/" + agreement_id) >diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementsShow.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementsShow.vue >index ef882e019b8..b7ef04dbb28 100644 >--- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementsShow.vue >+++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementsShow.vue >@@ -301,7 +301,6 @@ > <script> > import { inject } from "vue" > import { APIClient } from "../../fetch/api-client.js" >-import { setError } from "../../messages" > > export default { > setup() { >@@ -348,14 +347,13 @@ export default { > methods: { > async getAgreement(agreement_id) { > const client = APIClient.erm >- try { >- await client.agreements.get(agreement_id).then(data => { >+ client.agreements.get(agreement_id).then( >+ data => { > this.agreement = data > this.initialized = true >- }) >- } catch (err) { >- setError(err.message || err.statusText) >- } >+ }, >+ error => {} >+ ) > }, > }, > name: "AgreementsShow", >diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/fetch/http-client.js b/koha-tmpl/intranet-tmpl/prog/js/vue/fetch/http-client.js >index 83f474008b7..84311cb0c27 100644 >--- a/koha-tmpl/intranet-tmpl/prog/js/vue/fetch/http-client.js >+++ b/koha-tmpl/intranet-tmpl/prog/js/vue/fetch/http-client.js >@@ -14,7 +14,7 @@ class HttpClient { > options = {}, > return_response = false > ) { >- let res; >+ let res, error; > await fetch(this._baseURL + endpoint, { > ...options, > headers: { ...this._headers, ...headers }, >@@ -24,13 +24,18 @@ class HttpClient { > (result) => { > res = result; > }, >- (error) => { >- setError(error.toString()); >+ (err) => { >+ error = err; >+ setError(err.toString()); > } > ) >- .catch((error) => { >- setError(error); >+ .catch((err) => { >+ error = err; >+ setError(err); > }); >+ >+ if (error) throw Error(error); >+ > return res; > } > >-- >2.37.1 (Apple Git-137.1)
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 32939
:
146470
|
146509
|
146642
|
146644
|
146645
|
146668
|
146669
|
146670
|
146671
|
146672
|
146674
|
146675
|
146676
|
146677
|
146678
|
146679
|
146680
|
146681
|
146682
|
147029
|
147030
|
147031
|
147032
|
147033
|
147034
|
147035
|
147036
|
147037
|
147038
|
147039
|
147040
|
147041
|
147042
|
147043
|
147044
|
147056
|
147057
|
147059
|
147060
|
147061
|
147062
|
147063
|
147064
|
147065
|
147066
|
147067
|
147068
|
147069
|
147070
|
147071
|
147072
|
147073
|
147306
|
147307
|
147308
|
147309
|
147310
|
147311
|
147312
|
147313
|
147314
|
147315
|
147316
|
147317
|
147318
|
147319
|
147320
|
147321
|
147322
|
147332
|
149441