View | Details | Raw Unified | Return to bug 32939
Collapse All | Expand All

(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/fetch/http-client.js (-4 / +17 lines)
Lines 8-20 class HttpClient { Link Here
8
        };
8
        };
9
    }
9
    }
10
10
11
    async _fetchJSON(endpoint, headers = {}, options = {}) {
11
    async _fetchJSON(endpoint, headers = {}, options = {}, return_response = false) {
12
        let res;
12
        let res;
13
        await fetch(this._baseURL + endpoint, {
13
        await fetch(this._baseURL + endpoint, {
14
            ...options,
14
            ...options,
15
            headers: { ...this._headers, ...headers },
15
            headers: { ...this._headers, ...headers },
16
        })
16
        })
17
            .then(this.checkError)
17
            .then((response) => this.checkError(response, return_response))
18
            .then(
18
            .then(
19
                (result) => {
19
                (result) => {
20
                    res = result;
20
                    res = result;
Lines 60-65 class HttpClient { Link Here
60
        });
60
        });
61
    }
61
    }
62
62
63
    count(params = {}) {
64
      let res;
65
      this._fetchJSON(params.endpoint, params.headers, 1).then(
66
          (response) => {
67
              if (response) {
68
                  res = response.headers.get("X-Total-Count");
69
              }
70
          },
71
          (error) => {
72
              setError(error.toString());
73
          }
74
      );
75
      return res;
76
    }
77
63
    checkError(response, return_response = 0) {
78
    checkError(response, return_response = 0) {
64
        if (response.status >= 200 && response.status <= 299) {
79
        if (response.status >= 200 && response.status <= 299) {
65
            return return_response ? response : response.json();
80
            return return_response ? response : response.json();
Lines 70-76 class HttpClient { Link Here
70
        }
85
        }
71
    }
86
    }
72
87
73
    //TODO: Implement count method
74
}
88
}
75
89
76
export default HttpClient;
90
export default HttpClient;
77
- 

Return to bug 32939