fix(nui): Don't throw failed to fetch error in browser

This commit is contained in:
Luke committed 2022-01-01 13:21:17 +01:00
1 parent 4529361e92
commit 2fc0aa4de9
1 file changed
+4
+4
View File
@@ -9,6 +9,8 @@
* @return returnData - A promise for the data sent back by the NuiCallbacks CB argument
*/
import { isEnvBrowser } from "./misc";
export async function fetchNui<T = any>(eventName: string, data?: any): Promise<T> {
const options = {
method: 'post',
@@ -18,6 +20,8 @@ export async function fetchNui<T = any>(eventName: string, data?: any): Promise<
body: JSON.stringify(data),
};
if (isEnvBrowser()) return undefined as any;
const resourceName = (window as any).GetParentResourceName ? (window as any).GetParentResourceName() : 'nui-frame-app';
const resp = await fetch(`https://${resourceName}/${eventName}`, options);