Enable use unknown in catch variables (#2784)

* Enable use unknown in catch variables rule

* Add type guards in useAuthProvider

* Add type cast in FilterErrorsList

* Handle error in tasks
This commit is contained in:
Michał Droń 2022-12-07 11:00:42 +01:00 committed by GitHub
parent 443a94834e
commit b0ba5cc2ab
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 17 additions and 4 deletions

View file

@ -157,7 +157,11 @@ export function useAuthProvider({
return result.data.tokenCreate; return result.data.tokenCreate;
} catch (error) { } catch (error) {
handleLoginError(error); if (error instanceof ApolloError) {
handleLoginError(error);
} else {
setErrors(["unknownLoginError"]);
}
} }
}; };
@ -195,7 +199,11 @@ export function useAuthProvider({
return result?.data?.externalObtainAccessTokens; return result?.data?.externalObtainAccessTokens;
} catch (error) { } catch (error) {
handleLoginError(error); if (error instanceof ApolloError) {
handleLoginError(error);
} else {
setErrors(["unknownLoginError"]);
}
} }
}; };

View file

@ -55,7 +55,7 @@ const FilterErrorsList: React.FC<FilterErrorsListProps> = ({
{ dependencies: dependencies?.join() }, { dependencies: dependencies?.join() },
); );
} catch (e) { } catch (e) {
errorTracker.captureException(e); errorTracker.captureException(e as Error);
console.warn("Translation missing for filter error code: ", code); console.warn("Translation missing for filter error code: ", code);
return intl.formatMessage(validationMessages.UNKNOWN_ERROR); return intl.formatMessage(validationMessages.UNKNOWN_ERROR);
} }

View file

@ -37,7 +37,11 @@ export async function handleTask(task: QueuedTask): Promise<TaskStatus> {
}); });
} }
} catch (error) { } catch (error) {
task.onError(error); if (error instanceof Error) {
task.onError(error);
} else {
console.error("Unknown error", error);
}
} }
return status; return status;

View file

@ -15,6 +15,7 @@
"noImplicitThis": true, "noImplicitThis": true,
"alwaysStrict": true, "alwaysStrict": true,
"strictBindCallApply": true, "strictBindCallApply": true,
"useUnknownInCatchVariables": true,
"paths": { "paths": {
"@assets/*": ["assets/*"], "@assets/*": ["assets/*"],
"@locale/*": ["locale/*"], "@locale/*": ["locale/*"],