Bugzilla – Attachment 147309 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: Restore checkError
Bug-32939-Restore-checkError.patch (text/plain), 2.29 KB, created by
Nick Clemens (kidclamp)
on 2023-02-24 12:22:34 UTC
(
hide
)
Description:
Bug 32939: Restore checkError
Filename:
MIME Type:
Creator:
Nick Clemens (kidclamp)
Created:
2023-02-24 12:22:34 UTC
Size:
2.29 KB
patch
obsolete
>From 008ec997151702019a99741260db892cd5fbdaba Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Wed, 15 Feb 2023 10:36:38 +0100 >Subject: [PATCH] Bug 32939: Restore checkError > >Signed-off-by: Matt Blenkinsop <matt.blenkinsop@ptfs-europe.com> >Signed-off-by: Nick Clemens <nick@bywatersolutions.com> >--- > .../prog/js/vue/fetch/http-client.js | 37 ++++++++++++++----- > 1 file changed, 28 insertions(+), 9 deletions(-) > >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 63731a5657..d1b5a917b9 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 >@@ -1,3 +1,5 @@ >+import { setError } from "../messages"; >+ > class HttpClient { > constructor(options = {}) { > this._baseURL = options.baseURL || ""; >@@ -7,17 +9,24 @@ class HttpClient { > } > > async _fetchJSON(endpoint, headers = {}, options = {}) { >- const res = await fetch(this._baseURL + endpoint, { >+ let res; >+ await fetch(this._baseURL + endpoint, { > ...options, > headers: { ...this._headers, ...headers }, >- }); >- >- if (!res.ok) throw new Error(res.statusText); >- >- if (options.parseResponse !== false && res.status !== 204) >- return res.json(); >- >- return undefined; >+ }) >+ .then(this.checkError) >+ .then( >+ (result) => { >+ res = result; >+ }, >+ (error) => { >+ setError(error.toString()); >+ } >+ ) >+ .catch((error) => { >+ setError(error); >+ }); >+ return res; > } > > get(params = {}) { >@@ -51,6 +60,16 @@ class HttpClient { > }); > } > >+ checkError(response, return_response = 0) { >+ if (response.status >= 200 && response.status <= 299) { >+ return return_response ? response : response.json(); >+ } else { >+ console.log("Server returned an error:"); >+ console.log(response); >+ throw Error("%s (%s)".format(response.statusText, response.status)); >+ } >+ } >+ > //TODO: Implement count method > } > >-- >2.30.2
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