Skip to content

fix(utils): stop returning mockData on timeout#541

Open
simsonas86 wants to merge 2 commits intoProject-Sloth:mainfrom
simsonas86:patch-nui-callback-handling
Open

fix(utils): stop returning mockData on timeout#541
simsonas86 wants to merge 2 commits intoProject-Sloth:mainfrom
simsonas86:patch-nui-callback-handling

Conversation

@simsonas86
Copy link
Copy Markdown

Changes summary:

mockData still gets returned when isEnvBrowser is true, but it's handled in the main try block instead of when a request times out and is caught. This prevents unwanted behaviour like a permission bypass if mockData contains { isBoss: true } e.g.

/** Fetches the current player's permissions from the server */
async function loadPermissions(): Promise<void> {
try {
const response = await fetchNui<{ permissions?: string[]; isBoss?: boolean }>(
NUI_EVENTS.AUTH.GET_MY_PERMISSIONS,
{},
{ permissions: [], isBoss: true },
);
permissions = response?.permissions || [];
isBoss = response?.isBoss || false;
} catch (error) {
debugError("Failed to load permissions:", error);
// On failure, default to no permissions (safe)
permissions = [];
isBoss = false;
}
}

Removed the ability to return mockData after catching an error entirely.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant