From ef7da71ad587b8caa9bcd237b4f0df6d8d221d65 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 15 Feb 2023 10:13:58 +0100 Subject: [PATCH] Bug 32939: Set the default header at lower level Signed-off-by: Matt Blenkinsop Signed-off-by: Nick Clemens Signed-off-by: Tomas Cohen Arazi (cherry picked from commit 5871db79587436bc28eb04f0558f2423ecfcac8c) Signed-off-by: Matt Blenkinsop --- .../intranet-tmpl/prog/js/vue/fetch/erm-api-client.js | 5 +---- .../intranet-tmpl/prog/js/vue/fetch/http-client.js | 10 ++++------ 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/fetch/erm-api-client.js b/koha-tmpl/intranet-tmpl/prog/js/vue/fetch/erm-api-client.js index bdad9f6b17..e16e35b2b5 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/fetch/erm-api-client.js +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/fetch/erm-api-client.js @@ -24,23 +24,20 @@ export class ERMAPIClient extends HttpClient { delete: (id) => this.delete({ endpoint: "agreements/" + id, - headers: this.getDefaultJSONPayloadHeader(), }), create: (agreement) => this.post({ endpoint: "agreements", body: agreement, - headers: this.getDefaultJSONPayloadHeader(), }), update: (agreement, id) => this.put({ endpoint: "agreements/" + id, body: agreement, - headers: this.getDefaultJSONPayloadHeader(), }), //count: () => this.count("agreements"), //TODO: Implement count method }; } } -export default ERMAPIClient; \ No newline at end of file +export default ERMAPIClient; 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 6a47276dcf..63731a5657 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,12 +1,15 @@ class HttpClient { constructor(options = {}) { this._baseURL = options.baseURL || ""; + this._headers = options.headers || { + "Content-Type": "application/json;charset=utf-8", + }; } async _fetchJSON(endpoint, headers = {}, options = {}) { const res = await fetch(this._baseURL + endpoint, { ...options, - headers: headers, + headers: { ...this._headers, ...headers }, }); if (!res.ok) throw new Error(res.statusText); @@ -18,7 +21,6 @@ class HttpClient { } get(params = {}) { - console.log(params); return this._fetchJSON(params.endpoint, params.headers, { ...params.options, method: "GET", @@ -50,10 +52,6 @@ class HttpClient { } //TODO: Implement count method - - getDefaultJSONPayloadHeader() { - return { "Content-Type": "application/json;charset=utf-8" }; - } } export default HttpClient; -- 2.39.5