From 7b7740563eb471092b9e2b3e7830f02c54866012 Mon Sep 17 00:00:00 2001 From: Michael Shamoon <4887959+shamoon@users.noreply.github.com> Date: Sat, 22 Oct 2022 22:48:25 -0700 Subject: [PATCH 1/8] Basic widget data validation --- public/locales/en/common.json | 6 ++- src/components/services/widget/error.jsx | 48 ++++++++++++++++++++++++ src/utils/proxy/handlers/credentialed.js | 5 +++ src/utils/proxy/handlers/generic.js | 7 ++++ src/utils/proxy/http.js | 2 +- src/utils/proxy/validate-widget-data.js | 22 +++++++++++ 6 files changed, 88 insertions(+), 2 deletions(-) create mode 100644 src/components/services/widget/error.jsx create mode 100644 src/utils/proxy/validate-widget-data.js diff --git a/public/locales/en/common.json b/public/locales/en/common.json index cc946e783..c4b41f057 100644 --- a/public/locales/en/common.json +++ b/public/locales/en/common.json @@ -13,7 +13,11 @@ "widget": { "missing_type": "Missing Widget Type: {{type}}", "api_error": "API Error", - "status": "Status" + "status": "Status", + "debug_info": "Debug Information", + "url": "URL", + "raw_error": "Raw Error", + "response_data": "Response Data" }, "weather": { "current": "Current Location", diff --git a/src/components/services/widget/error.jsx b/src/components/services/widget/error.jsx new file mode 100644 index 000000000..a6d400e8d --- /dev/null +++ b/src/components/services/widget/error.jsx @@ -0,0 +1,48 @@ +import { useTranslation } from "react-i18next"; + +function displayError(error) { + return JSON.stringify(error[1] ? error[1] : error, null, 4); +} + +function displayData(data) { + return (data.type === 'Buffer') ? Buffer.from(data).toString() : JSON.stringify(data, 4); +} + +export default function Error({ error }) { + const { t } = useTranslation(); + + if (error?.data?.error) { + error = error.data.error; // eslint-disable-line no-param-reassign + } + + return ( +