UI: don't error when tariff is missing (#20211)

This commit is contained in:
Michael Geers 2025-03-28 11:40:21 +01:00 • committed by GitHub
parent bba19aa2f9
commit e48829dc6f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 16 additions and 13 deletions

View file

@ -60,3 +60,9 @@ export const i18n = axios.create({
Accept: "application/toml",
},
});
export const allowClientError = {
validateStatus(status) {
return status >= 200 && status < 500;
},
};

View file

@ -69,7 +69,7 @@ import RepeatingSettings from "./PlansRepeatingSettings.vue";
import Warnings from "./Warnings.vue";
import formatter from "../../mixins/formatter.js";
import collector from "../../mixins/collector.js";
import api from "../../api.js";
import api, { allowClientError } from "../../api.js";
import CustomSelect from "../Helper/CustomSelect.vue";
import deepEqual from "../../utils/deepEqual.js";
@ -287,11 +287,7 @@ export default {
return;
}
const tariffRes = await api.get(`tariff/planner`, {
validateStatus(status) {
return status >= 200 && status < 500;
},
});
const tariffRes = await api.get(`tariff/planner`, allowClientError);
if (tariffRes.status === 404) {
this.tariff = { rates: [] };
} else {

View file

@ -211,7 +211,7 @@ import TelemetrySettings from "../TelemetrySettings.vue";
import CustomSelect from "../Helper/CustomSelect.vue";
import co2Reference from "./co2Reference.js";
import settings from "../../settings.js";
import api from "../../api.js";
import api, { allowClientError } from "../../api.js";
import { docsPrefix } from "../../i18n.js";
export default {
@ -321,9 +321,7 @@ export default {
},
async updateReferenceGrid() {
try {
const res = await api.get(`tariff/grid`, {
validateStatus: (status) => status >= 200 && status < 500,
});
const res = await api.get(`tariff/grid`, allowClientError);
const { rates } = res.data.result;
this.referenceGrid =
rates.reduce((acc, slot) => {

View file

@ -86,7 +86,7 @@
import formatter from "../../mixins/formatter.js";
import TariffChart from "./TariffChart.vue";
import { CO2_TYPE } from "../../units.js";
import api from "../../api.js";
import api, { allowClientError } from "../../api.js";
export default {
name: "SmartCostLimit",
@ -258,8 +258,11 @@ export default {
},
async updateTariff() {
try {
this.tariff = (await api.get(`tariff/planner`)).data.result;
this.startTime = new Date();
const tariffRes = await api.get(`tariff/planner`, allowClientError);
if (tariffRes.status === 200) {
this.tariff = tariffRes.data.result;
this.startTime = new Date();
}
} catch (e) {
console.error(e);
}