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

View File

@@ -1,5 +1,5 @@
import { PluginError, PluginMeta, renderMarkdown } from '@grafana/data';
import { getBackendSrv } from '@grafana/runtime';
import { getBackendSrv, isFetchError } from '@grafana/runtime';
import { API_ROOT, GCOM_API_ROOT } from './constants';
import { isLocalPluginVisible, isRemotePluginVisible } from './helpers';
@@ -45,8 +45,10 @@ async function getRemotePlugin(id: string): Promise<RemotePlugin | undefined> {
try {
return await getBackendSrv().get(`${GCOM_API_ROOT}/plugins/${id}`, {});
} catch (error) {
// It can happen that GCOM is not available, in that case we show a limited set of information to the user.
error.isHandled = true;
if (isFetchError(error)) {
// It can happen that GCOM is not available, in that case we show a limited set of information to the user.
error.isHandled = true;
}
return;
}
}
@@ -66,8 +68,10 @@ async function getPluginVersions(id: string, isPublished: boolean): Promise<Vers
grafanaDependency: v.grafanaDependency,
}));
} catch (error) {
// It can happen that GCOM is not available, in that case we show a limited set of information to the user.
error.isHandled = true;
if (isFetchError(error)) {
// It can happen that GCOM is not available, in that case we show a limited set of information to the user.
error.isHandled = true;
}
return [];
}
}
@@ -79,7 +83,9 @@ async function getLocalPluginReadme(id: string): Promise<string> {
return markdownAsHtml;
} catch (error) {
error.isHandled = true;
if (isFetchError(error)) {
error.isHandled = true;
}
return '';
}
}

View File

@@ -1,7 +1,7 @@
import { createAction, createAsyncThunk, Update } from '@reduxjs/toolkit';
import { PanelPlugin } from '@grafana/data';
import { getBackendSrv } from '@grafana/runtime';
import { getBackendSrv, isFetchError } from '@grafana/runtime';
import { importPanelPlugin } from 'app/features/plugins/importPanelPlugin';
import { StoreState, ThunkResult } from 'app/types';
@@ -39,7 +39,9 @@ export const fetchRemotePlugins = createAsyncThunk<RemotePlugin[], void, { rejec
try {
return await getRemotePlugins();
} catch (error) {
error.isHandled = true;
if (isFetchError(error)) {
error.isHandled = true;
}
return thunkApi.rejectWithValue([]);
}
}