Implement better error handling for MySpeed widget

Co-authored-by: shamoon <4887959+shamoon@users.noreply.github.com>
This commit is contained in:
Mathias Wagner 2024-06-23 20:27:54 +02:00 committed by GitHub
parent 5c7b63764f
commit 6a8b933d43
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -9,8 +9,16 @@ export default function Component({ service }) {
const { widget } = service;
const { data, error } = useWidgetAPI(widget, "info");
if (error) {
return <Container service={service} error={error} />;
if (error || (data && data.message) || (data && data[0] && data[0].error)) {
let finalError = error ?? data;
if (data && data[0] && data[0].error) {
try {
finalError = JSON.parse(data[0].error);
} catch (e) {
finalError = data[0].error;
}
}
return <Container service={service} error={finalError} />;
}
if (!data) {