Bugzilla – Attachment 154097 Details for
Bug 34448
ERM should be able to display error messages coming from the API
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 34448: Update the way we handle response in http-client.js
Bug-34448-Update-the-way-we-handle-response-in-htt.patch (text/plain), 2.48 KB, created by
Pedro Amorim
on 2023-07-31 14:57:35 UTC
(
hide
)
Description:
Bug 34448: Update the way we handle response in http-client.js
Filename:
MIME Type:
Creator:
Pedro Amorim
Created:
2023-07-31 14:57:35 UTC
Size:
2.48 KB
patch
obsolete
>From a50d10f9ea4b90f6a7a37cb0efd578805db03ac3 Mon Sep 17 00:00:00 2001 >From: Pedro Amorim <pedro.amorim@ptfs-europe.com> >Date: Mon, 31 Jul 2023 14:57:06 +0000 >Subject: [PATCH] Bug 34448: Update the way we handle response in > http-client.js > >Test plan: >Before patch: >- Visit a non-existent ID i.e. /cgi-bin/koha/erm/agreements/999 >- Visit a char ID i.e. /cgi-bin/koha/erm/agreements/abc > >Apply patch: >Repeat above steps. > >Run cypress tests >--- > .../prog/js/vue/fetch/http-client.js | 34 ++++++++----------- > 1 file changed, 15 insertions(+), 19 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 936231c3f6..481eba897c 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 >@@ -21,16 +21,22 @@ class HttpClient { > ...options, > headers: { ...this._headers, ...headers }, > }) >- .then(response => this.checkError(response, return_response)) >- .then( >- result => { >- res = result; >- }, >- err => { >- error = err; >- setError(err.toString()); >+ .then(response => { >+ if (!response.ok) { >+ return response.text().then(text => { >+ let json = JSON.parse(text); >+ let message = >+ json.error || >+ json.errors.map(e => e.message).join(" ") || >+ json; >+ throw new Error(`${message}`); >+ }); > } >- ) >+ return return_response ? response : response.json(); >+ }) >+ .then(result => { >+ res = result; >+ }) > .catch(err => { > error = err; > setError(err); >@@ -143,16 +149,6 @@ class HttpClient { > method: "PATCH", > }); > } >- >- 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)); >- } >- } > } > > export default HttpClient; >-- >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 34448
:
154097
|
154098
|
154099
|
154123
|
154124
|
154259
|
154260