refactor(theme-common): unify missing context errors (#6826)

* refactor(theme-common): unify missing context errors

* update test

* more robust
This commit is contained in:
Joshua Chen 2022-03-03 22:26:56 +08:00 committed by GitHub
parent 5c60f41e1b
commit c387a177e8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 35 additions and 28 deletions

View file

@ -19,6 +19,7 @@ import type {
PropSidebarBreadcrumbsItem,
} from '@docusaurus/plugin-content-docs';
import {isSamePath} from './pathUtils';
import {ReactContextError} from './reactUtils';
import {useLocation} from '@docusaurus/router';
// TODO not ideal, see also "useDocs"
@ -49,7 +50,7 @@ export function DocsVersionProvider({
export function useDocsVersion(): PropVersionMetadata {
const version = useContext(DocsVersionContext);
if (version === EmptyContextValue) {
throw new Error('This hook requires usage of <DocsVersionProvider>');
throw new ReactContextError('DocsVersionProvider');
}
return version;
}
@ -89,7 +90,7 @@ export function DocsSidebarProvider({
export function useDocsSidebar(): PropSidebar | null {
const sidebar = useContext(DocsSidebarContext);
if (sidebar === EmptyContextValue) {
throw new Error('This hook requires usage of <DocsSidebarProvider>');
throw new ReactContextError('DocsSidebarProvider');
}
return sidebar;
}