1- import { useMemo } from "react" ;
1+ import React , { useMemo } from "react" ;
22import {
33 Alert ,
44 Box ,
@@ -13,13 +13,14 @@ import { Refresh as RefreshIcon } from "@mui/icons-material";
1313import { g3BorderRadius , G3_PRESETS } from "@/theme/g3Curves" ;
1414import { useI18n } from "@/contexts/I18nContext" ;
1515import type { InterpolationOptions } from "@/utils/i18n/types" ;
16+ import { SearchIndexErrorCode } from "@/services/github/core/searchIndex/errors" ;
1617
1718const FALLBACK_INDEX_TIME = Date . now ( ) ;
1819
1920interface IndexStatusProps {
2021 enabled : boolean ;
2122 loading : boolean ;
22- error : { message : string ; code ?: string } | null ;
23+ error : { message : string ; code ?: SearchIndexErrorCode } | null ;
2324 ready : boolean ;
2425 indexedBranches : string [ ] ;
2526 lastUpdatedAt : number | undefined ;
@@ -32,50 +33,52 @@ interface ErrorScenario {
3233}
3334
3435const getErrorScenario = (
35- error : { message : string ; code ?: string } | null ,
36+ error : { message : string ; code ?: SearchIndexErrorCode } | null ,
3637 ready : boolean ,
3738 t : ( key : string , options ?: InterpolationOptions ) => string
3839) : ErrorScenario | null => {
39- if ( error ?. code !== undefined ) {
40- switch ( error . code ) {
41- case 'SEARCH_INDEX_MANIFEST_NOT_FOUND' :
42- return {
43- title : t ( 'search.index.errors.manifestNotFound.title' ) ,
44- description : [
45- t ( 'search.index.errors.manifestNotFound.description1' ) ,
46- t ( 'search.index.errors.manifestNotFound.description2' ) ,
47- ] ,
48- } ;
49- case 'SEARCH_INDEX_MANIFEST_INVALID' :
50- return {
51- title : t ( 'search.index.errors.manifestInvalid.title' ) ,
52- description : [ t ( 'search.index.errors.manifestInvalid.description1' ) ] ,
53- } ;
54- case 'SEARCH_INDEX_FILE_NOT_FOUND' :
55- return {
56- title : t ( 'search.index.errors.fileNotFound.title' ) ,
57- description : [
58- t ( 'search.index.errors.fileNotFound.description1' ) ,
59- t ( 'search.index.errors.fileNotFound.description2' ) ,
60- ] ,
61- } ;
62- case 'SEARCH_INDEX_DOCUMENT_INVALID' :
63- return {
64- title : t ( 'search.index.errors.documentInvalid.title' ) ,
65- description : [
66- t ( 'search.index.errors.documentInvalid.description1' ) ,
67- t ( 'search.index.errors.documentInvalid.description2' ) ,
68- ] ,
69- } ;
70- default :
71- return {
72- title : t ( 'search.index.errors.default.title' ) ,
73- description : [
74- t ( 'search.index.errors.default.description1' , { message : error . message } ) ,
75- t ( 'search.index.errors.default.description2' ) ,
76- ] ,
77- } ;
40+ if ( error !== null ) {
41+ const code = error . code ;
42+ if ( code === SearchIndexErrorCode . MANIFEST_NOT_FOUND ) {
43+ return {
44+ title : t ( 'search.index.errors.manifestNotFound.title' ) ,
45+ description : [
46+ t ( 'search.index.errors.manifestNotFound.description1' ) ,
47+ t ( 'search.index.errors.manifestNotFound.description2' ) ,
48+ ] ,
49+ } ;
7850 }
51+ if ( code === SearchIndexErrorCode . MANIFEST_INVALID ) {
52+ return {
53+ title : t ( 'search.index.errors.manifestInvalid.title' ) ,
54+ description : [ t ( 'search.index.errors.manifestInvalid.description1' ) ] ,
55+ } ;
56+ }
57+ if ( code === SearchIndexErrorCode . INDEX_FILE_NOT_FOUND ) {
58+ return {
59+ title : t ( 'search.index.errors.fileNotFound.title' ) ,
60+ description : [
61+ t ( 'search.index.errors.fileNotFound.description1' ) ,
62+ t ( 'search.index.errors.fileNotFound.description2' ) ,
63+ ] ,
64+ } ;
65+ }
66+ if ( code === SearchIndexErrorCode . INDEX_DOCUMENT_INVALID ) {
67+ return {
68+ title : t ( 'search.index.errors.documentInvalid.title' ) ,
69+ description : [
70+ t ( 'search.index.errors.documentInvalid.description1' ) ,
71+ t ( 'search.index.errors.documentInvalid.description2' ) ,
72+ ] ,
73+ } ;
74+ }
75+ return {
76+ title : t ( 'search.index.errors.default.title' ) ,
77+ description : [
78+ t ( 'search.index.errors.default.description1' , { message : error . message } ) ,
79+ t ( 'search.index.errors.default.description2' ) ,
80+ ] ,
81+ } ;
7982 }
8083
8184 if ( ! ready ) {
0 commit comments