Procházet zdrojové kódy

fix json validator

AykutSarac před 2 roky
rodič
revize
67b5d6a1f8
1 změnil soubory, kde provedl 9 přidání a 10 odebrání
  1. 9 10
      src/components/MonacoEditor/index.tsx

+ 9 - 10
src/components/MonacoEditor/index.tsx

@@ -58,18 +58,17 @@ export const MonacoEditor = ({
 
   React.useEffect(() => {
     const formatTimer = setTimeout(() => {
-      try {
-        if (!value) {
-          setHasError(false);
-          return setJson("{}");
-        }
-
-        const parsedJSON = JSON.stringify(parse(value), null, 2);
-        setJson(parsedJSON);
+      if (!value) {
         setHasError(false);
-      } catch (jsonError: any) {
-        setHasError(true);
+        return setJson("{}");
       }
+
+      const errors = [];
+      const parsedJSON = JSON.stringify(parse(value, errors), null, 2);
+      if (errors.length) return setHasError(true);
+
+      setJson(parsedJSON);
+      setHasError(false);
     }, 1200);
 
     return () => clearTimeout(formatTimer);