🐽 Makes model-loading use result type for error handling
This commit is contained in:
+9
-3
@@ -15,9 +15,15 @@
|
|||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
socketService.connect(socketLocation);
|
socketService.connect(socketLocation);
|
||||||
registerFetchIntercept()
|
registerFetchIntercept()
|
||||||
const [urdf, JOINT_NAME] = await loadModelAsync('/spot_micro.urdf.xacro')
|
const modelRes = await loadModelAsync('/spot_micro.urdf.xacro')
|
||||||
jointNames.set(JOINT_NAME)
|
|
||||||
model.set(urdf)
|
if (modelRes.isOk()) {
|
||||||
|
const [urdf, JOINT_NAME] = modelRes.inner
|
||||||
|
jointNames.set(JOINT_NAME)
|
||||||
|
model.set(urdf)
|
||||||
|
} else {
|
||||||
|
console.error(modelRes.inner, {"exception": modelRes.exception})
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const registerFetchIntercept = () => {
|
const registerFetchIntercept = () => {
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
import { LoaderUtils } from "three";
|
import { LoaderUtils } from "three";
|
||||||
import URDFLoader, { type URDFRobot } from "urdf-loader"
|
import URDFLoader, { type URDFRobot } from "urdf-loader"
|
||||||
import { XacroLoader } from "xacro-parser"
|
import { XacroLoader } from "xacro-parser"
|
||||||
|
import { Result } from "$lib/utilities";
|
||||||
|
|
||||||
export const loadModelAsync = async (url:string):Promise<[URDFRobot, string[]]> => {
|
export const loadModelAsync = async (url:string):Promise<Result<[URDFRobot, string[]], string>> => {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const xacroLoader = new XacroLoader();
|
const xacroLoader = new XacroLoader();
|
||||||
|
|
||||||
@@ -22,9 +23,9 @@ export const loadModelAsync = async (url:string):Promise<[URDFRobot, string[]]>
|
|||||||
.filter(joint => joint[1].jointType !== 'fixed')
|
.filter(joint => joint[1].jointType !== 'fixed')
|
||||||
.map(joint => joint[0])
|
.map(joint => joint[0])
|
||||||
|
|
||||||
resolve([model, joints]);
|
resolve(Result.ok([model, joints]));
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
reject(error);
|
resolve(Result.err("Failed to load model", error));
|
||||||
}
|
}
|
||||||
}, (error) => reject(error));
|
}, (error) => reject(error));
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user