Chore: Enable useUnknownInCatchVariables for stricter type checking in catch blocks (#50591)

* wrap a bunch of errors

* wrap more things!

* fix up some unit tests

* wrap more errors

* tiny bit of tidy up
This commit is contained in:
Ashley Harrison
2022-06-15 08:59:29 +01:00
committed by GitHub
parent 2fbe99c1be
commit 803473f479
62 changed files with 364 additions and 177 deletions
@@ -1,6 +1,7 @@
import React, { useCallback, useEffect, useState } from 'react';
import { useAsync, useDebounce } from 'react-use';
import { isFetchError } from '@grafana/runtime';
import { Button, Field, Input, Modal } from '@grafana/ui';
import { FolderPicker } from 'app/core/components/Select/FolderPicker';
@@ -36,7 +37,9 @@ export const AddLibraryPanelContents = ({ panel, initialFolderId, onDismiss }: A
try {
return !(await getLibraryPanelByName(panelName)).some((lp) => lp.folderId === folderId);
} catch (err) {
err.isHandled = true;
if (isFetchError(err)) {
err.isHandled = true;
}
return true;
} finally {
setWaiting(false);
@@ -2,6 +2,7 @@ import { useEffect } from 'react';
import { useDispatch } from 'react-redux';
import useAsyncFn from 'react-use/lib/useAsyncFn';
import { isFetchError } from '@grafana/runtime';
import { notifyApp } from 'app/core/actions';
import { PanelModel } from 'app/features/dashboard/state';
@@ -17,8 +18,11 @@ export const usePanelSave = () => {
try {
return await saveAndRefreshLibraryPanel(panel, folderId);
} catch (err) {
err.isHandled = true;
throw new Error(err.data.message);
if (isFetchError(err)) {
err.isHandled = true;
throw new Error(err.data.message);
}
throw err;
}
}, []);