How about defining a function to fetch your user to always resolve to a User
?
Something like:
interface User {
name: string
}
export const fetchUser = async (): Promise<User> => {
try {
const response = await fetch('api.com/user')
return (await reponse.json()) as User;
} catch (error) {
return { name: 'Anonymous' }
}
}
Keep in mind that request failures can still be visible in the network tab of the developer console.