79205179

Date: 2024-11-19 22:04:40
Score: 2
Natty:
Report link

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.

Reasons:
  • RegEx Blacklisted phrase (1.5): resolve to a User?
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Starts with a question (0.5): How
Posted by: moonstar-x