---
name: valec3/frontend-data-error-handling
source: https://app.decimal.ai/s/valec3-frontend-data-error-handling@1/SKILL.md
source_sha256: 9257e6ce0454
---

# Frontend Data Error Handling

## When to use this skill
- Handling API errors
- Showing error messages
- Implementing retry logic
- Error boundaries

## Workflow
- [ ] Catch errors at API layer
- [ ] Show user-friendly messages
- [ ] Log errors for debugging
- [ ] Implement retry for transient errors
- [ ] Use error boundaries for crashes

## Instructions

### API Error Handling
```typescript
try {
  const data = await fetchUser(id);
  return data;
} catch (error) {
  if (error.response?.status === 404) {
    throw new NotFoundError('User not found');
  }
  if (error.response?.status >= 500) {
    throw new ServerError('Server error, please try again');
  }
  throw error;
}
```

### React Error Boundary
```typescript
class ErrorBoundary extends React.Component {
  state = { hasError: false, error: null };

  static getDerivedStateFromError(error) {
    return { hasError: true, error };
  }

  componentDidCatch(error, errorInfo) {
    console.error('Error:', error, errorInfo);
  }

  render() {
    if (this.state.hasError) {
      return <ErrorFallback error={this.state.error} />;
    }
    return this.props.children;
  }
}
```

## Resources
- Show friendly messages to users
- Log detailed errors for debugging
- Retry transient failures