- if (this.item.subtitle != null) return; // omitting unnecessary ajax call as the subtitle is showing
- var apikey = this.item.apikey;
- this.meal = await fetch(`${this.item.url}/api/meal-plans/today/`, {
- headers: {
- "Authorization": "Bearer " + this.item.apikey,
- "Accept": "application/json"
- }
- })
- .then(function(response) {
- if (!response.ok) {
- throw new Error("Not 2xx response")
- } else {
- if (response != null) {
- return response.json();
- }
- }
- })
- .catch((e) => console.log(e));
- this.stats = await fetch(`${this.item.url}/api/debug/statistics/`, {
- headers: {
- "Authorization": "Bearer " + this.item.apikey,
- "Accept": "application/json"
- }
- })
- .then(function(response) {
- if (!response.ok) {
- throw new Error("Not 2xx response")
- } else {
- return response.json();
- }
- })
- .catch((e) => console.log(e));
+ const headers = {
+ Authorization: "Bearer " + this.item.apikey,
+ Accept: "application/json",
+ };
+
+ if (this.item.subtitle != null) return;
+
+ this.meal = await this.fetch("/api/meal-plans/today/", { headers }).catch(
+ (e) => console.log(e)
+ );
+ this.stats = await this.fetch("/api/debug/statistics/", {
+ headers,
+ }).catch((e) => console.log(e));