sad-indigoS
Refine13mo ago
14 replies
sad-indigo

useGo throws errors

useGo seems to throw errors if it can't find the resource.

This should be handle more gracefully instead of throwing as will crash.


/**
* handle errors for resource
* @internal
*/
export const handleResourceErrors = (to: Resource, resource: IResourceItem) => {
if (!to?.action || !to?.resource) {
throw new Error([useGo]: "action" or "resource" is required.);
}

if (["edit", "show", "clone"].includes(to?.action) && !to.id) {
throw new Error(
[useGo]: [action: ${to.action}] requires an "id" for resource [resource: ${to.resource}],
);
}

const actionUrl = resource[to.action];
if (!actionUrl) {
throw new Error(
[useGo]: [action: ${to.action}] is not defined for [resource: ${to.resource}],
);
}
};
Was this page helpful?