Skip to content

Commit

Permalink
UI: better API errors (evcc-io#11602)
Browse files Browse the repository at this point in the history
  • Loading branch information
naltatis authored Jan 13, 2024
1 parent e7b78db commit d69b07c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
8 changes: 6 additions & 2 deletions assets/js/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,14 @@ const api = axios.create({
api.interceptors.response.use(
(response) => response,
(error) => {
let message = error.message;
const message = [`${error.message}.`];
if (error.response?.data?.error) {
message.push(`${error.response.data.error}.`);
}
if (error.config) {
const method = error.config.method.toUpperCase();
const url = error.config.baseURL + error.config.url;
message += `: API request failed ${url}`;
message.push(`${method} ${url}`);
}
window.app.raise({ message });
return Promise.reject(error);
Expand Down
15 changes: 11 additions & 4 deletions assets/js/components/Notifications.vue
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,13 @@
class="flex-grow-0 flex-shrink-0 d-block"
></shopicon-regular-exclamationtriangle>
<span class="flex-grow-1 px-2 py-1 text-break">
{{ message(msg) }}
<span
v-for="(line, idx) in message(msg)"
:key="idx"
class="d-block"
>
{{ line }}
</span>
</span>
<span v-if="msg.count > 1" class="badge rounded-pill bg-secondary">
{{ msg.count }}
Expand Down Expand Up @@ -107,11 +113,12 @@ export default {
},
methods: {
message({ message, lp }) {
let context = "";
const lines = Array.isArray(message) ? message : [message];
if (lp) {
context = `${this.loadpointTitles[lp - 1] || lp}: `;
// add loadpoint title to first line
lines[0] = `${this.loadpointTitles[lp - 1] || lp}: ${lines[0]}`;
}
return `${context}${message}`;
return lines;
},
clear: function () {
window.app && window.app.clear();
Expand Down

0 comments on commit d69b07c

Please sign in to comment.