diff --git a/assets/js/components/TargetCharge.vue b/assets/js/components/TargetCharge.vue index ad8170c01..e67e151a3 100644 --- a/assets/js/components/TargetCharge.vue +++ b/assets/js/components/TargetCharge.vue @@ -128,7 +128,7 @@ export default { timeTooFarInTheFuture: function () { if (this.tariff?.rates) { const lastRate = this.tariff.rates[this.tariff.rates.length - 1]; - if (lastRate.end) { + if (lastRate?.end) { const end = new Date(lastRate.end); return this.selectedTargetTime >= end; } @@ -201,13 +201,18 @@ export default { !isNaN(this.selectedTargetTime) ) { try { - const opts = { - params: { targetTime: this.selectedTargetTime }, - }; this.plan = ( - await api.get(`loadpoints/${this.id}/target/plan`, opts) + await api.get(`loadpoints/${this.id}/target/plan`, { + params: { targetTime: this.selectedTargetTime }, + }) ).data.result; - this.tariff = (await api.get(`tariff/planner`)).data.result; + + const tariffRes = await api.get(`tariff/planner`, { + validateStatus: function (status) { + return status >= 200 && status < 500; + }, + }); + this.tariff = tariffRes.status === 404 ? { rates: [] } : tariffRes.data.result; } catch (e) { console.error(e); } diff --git a/assets/js/components/TargetChargePlan.vue b/assets/js/components/TargetChargePlan.vue index 52573c6a9..0279f2965 100644 --- a/assets/js/components/TargetChargePlan.vue +++ b/assets/js/components/TargetChargePlan.vue @@ -5,7 +5,7 @@
{{ $t("main.targetChargePlan.chargeDuration") }}
{{ planDuration }}
-
+
{{ activeSlotName }} {{ $t("main.targetChargePlan.co2Label") }} @@ -46,6 +46,9 @@ export default { isCo2() { return this.unit === CO2_UNIT; }, + hasTariff() { + return this.rates?.length > 1; + }, avgPrice() { let hourSum = 0; let priceSum = 0; diff --git a/assets/js/components/TariffChart.vue b/assets/js/components/TariffChart.vue index 1b9f0d3ef..8792da204 100644 --- a/assets/js/components/TariffChart.vue +++ b/assets/js/components/TariffChart.vue @@ -18,7 +18,7 @@ @click="selectSlot(index)" >
- ? + ?
{{ slot.startHour }} @@ -89,9 +89,8 @@ export default { }, priceStyle(price) { const value = price === undefined ? this.avgPrice : price; - return { - height: `${(100 / this.maxPrice) * value}%`, - }; + const height = value ? `${(100 / this.maxPrice) * value}%` : "100%"; + return { height }; }, }, }; diff --git a/server/http_handler.go b/server/http_handler.go index f1eec3b00..7d97e9214 100644 --- a/server/http_handler.go +++ b/server/http_handler.go @@ -190,13 +190,13 @@ func tariffHandler(site site.API) http.HandlerFunc { t := site.GetTariff(tariff) if t == nil { - jsonError(w, http.StatusBadRequest, errors.New("tariff not available")) + jsonError(w, http.StatusNotFound, errors.New("tariff not available")) return } rates, err := t.Rates() if err != nil { - jsonError(w, http.StatusBadRequest, err) + jsonError(w, http.StatusNotFound, err) return }