Skip to content

Commit

Permalink
Track error status whwn mod list is partially loaded
Browse files Browse the repository at this point in the history
  • Loading branch information
VilppeRiskidev committed Feb 18, 2025
1 parent e8cc77f commit a151fd4
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions src/store/modules/TsModsModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ import { ActionTree, GetterTree, MutationTree } from 'vuex';
import { State as RootState } from '../index';
import ExportMod from '../../model/exports/ExportMod';
import ManifestV2 from '../../model/ManifestV2';
import R2Error from "../../model/errors/R2Error";
import ThunderstoreMod from '../../model/ThunderstoreMod';
import VersionNumber from '../../model/VersionNumber';
import CdnProvider from '../../providers/generic/connection/CdnProvider';
import * as PackageDb from '../../r2mm/manager/PackageDexieStore';
import { isEmptyArray, isStringArray } from '../../utils/ArrayUtils';
import { retry } from '../../utils/Common';
import { Deprecations } from '../../utils/Deprecations';
import { fetchAndProcessBlobFile, getAxiosWithTimeouts } from '../../utils/HttpUtils';
import { fetchAndProcessBlobFile, getAxiosWithTimeouts, isNetworkError } from '../../utils/HttpUtils';

export interface CachedMod {
tsMod: ThunderstoreMod | undefined;
Expand Down Expand Up @@ -45,6 +46,7 @@ function isPackageListChunk(value: unknown): value is PackageListChunk {
}

const EXCLUSIONS = 'https://raw.githubusercontent.com/ebkr/r2modmanPlus/master/modExclusions.md';
const PARTIAL_UPDATE_ERROR = 'Failed to fully refresh the online mod list. Some mod versions might be unavailable.';

/**
* For dealing with mods listed in communities, i.e. available through
Expand Down Expand Up @@ -124,6 +126,21 @@ export const TsModsModule = {
&& (Date.now() - state.modsLastUpdated.getTime()) > (1000 * 60 * 60);
},

/*** A more concise version of the error message */
conciseThunderstoreModListUpdateErrorMessage(state): string|undefined {
if (!state.thunderstoreModListUpdateError) {
return undefined;
}

let conciseError = "Failed to load mod list";
if (isNetworkError(state.thunderstoreModListUpdateError)) {
conciseError = "Failed to download mod list due to network error"
} else if (state.thunderstoreModListUpdateError.name === PARTIAL_UPDATE_ERROR) {
conciseError = "Failed to fully refresh the online mod list";
}
return conciseError;
},

/*** Return ThunderstoreMod representation of a ManifestV2 */
tsMod: (_state, getters) => (mod: ExportMod|ManifestV2): ThunderstoreMod | undefined => {
return getters.cachedMod(mod).tsMod;
Expand Down Expand Up @@ -258,7 +275,7 @@ export const TsModsModule = {
},

async fetchAndCachePackageListChunks(
{dispatch},
{commit, dispatch},
{packageListIndex, progressCallback}: {packageListIndex: PackageListIndex, progressCallback?: ProgressCallback},
): Promise<boolean> {
const chunkCount = packageListIndex.content.length;
Expand All @@ -283,6 +300,13 @@ export const TsModsModule = {
// hash is updated in the API.
if (successes === chunkCount) {
await dispatch('cacheIndexHash', packageListIndex.hash);
} else {
commit('setThunderstoreModListUpdateError',
new R2Error(
PARTIAL_UPDATE_ERROR,
`Only ${chunkCount - successes} out of ${chunkCount} chunks were updated successfully.`,
)
);
}

return successes === chunkCount;
Expand Down

0 comments on commit a151fd4

Please sign in to comment.