expert
expert
SSolidJS
Created by expert on 3/27/2024 in #support
Canonical way to handle exceptions in async functions to perform redirect?
Apparently I have to wrap async calls into [createResource][1] to make its exceptions to be catchable in [ErrorBoundary.fallback][2]. That was my page become something like this
export default function UserProfile() {
const context = useContext(SessionContext);

const [data, { mutate, refetch }] = createResource(() => api.currentUser())

return (
<AuthenticatedRoute>
<div>Hello, {context?.user?.firstName} {context?.user?.lastName}</div><br/>
<button onClick={refetch}>Refresh</button><br/>
<Suspense>
<div>Value: {data()?.email}</div>
</Suspense>
</AuthenticatedRoute>
);
}
export default function UserProfile() {
const context = useContext(SessionContext);

const [data, { mutate, refetch }] = createResource(() => api.currentUser())

return (
<AuthenticatedRoute>
<div>Hello, {context?.user?.firstName} {context?.user?.lastName}</div><br/>
<button onClick={refetch}>Refresh</button><br/>
<Suspense>
<div>Value: {data()?.email}</div>
</Suspense>
</AuthenticatedRoute>
);
}
If there is better way, pleas elet me know.
2 replies