Enchanted Error Handling

Error handling is where good code becomes great code. Anyone can handle the happy path. The question is: what happens when the forest gets dark?

The Happy Path Illusion

Your demo always works. The happy path is paved, lit, and has a gift shop at the end. Production is a different forest entirely — one where users do things you never imagined and networks fail in ways you didn’t know were possible.

Defensive by Default

async function fetchTransmission(id: string) {
  if (!id) return { error: "No signal ID provided" };
  
  try {
    const response = await api.get(`/transmissions/${id}`);
    if (!response.ok) {
      return { error: `Signal lost: ${response.status}` };
    }
    return { data: response.data };
  } catch (e) {
    return { error: "The deep currents are disrupted" };
  }
}

User-Facing Errors

Your users don’t care about stack traces. They care about what to do next. "Something went wrong" is a confession, not an error message. "Your session expired — please sign in again" is a path forward.

The abyss doesn’t pretend to be shallow. It tells you exactly how deep it is. That’s not discouraging — it’s respectful.

— JP, from the void.

Reply

Avatar

or to participate

Keep Reading