Skip to content

Error Handling ​

Fizzy MCP uses a functional error handling approach with the Result type. This provides type-safe error handling without exceptions.

Error Types ​

FizzyError ​

The base error type for all Fizzy API errors.

typescript
interface FizzyError {
  /** Error code for programmatic handling */
  code: ErrorCode;
  
  /** Human-readable error message */
  message: string;
  
  /** HTTP status code (if applicable) */
  status?: number;
  
  /** Original error (if wrapping another error) */
  cause?: Error;
}

Error Codes ​

CodeDescription
UNAUTHORIZEDInvalid or expired API token
FORBIDDENNo permission to access resource
NOT_FOUNDResource does not exist
VALIDATION_ERRORInvalid request parameters
RATE_LIMITEDToo many requests
SERVER_ERRORInternal server error
NETWORK_ERRORNetwork connectivity issue
UNKNOWNUnexpected error

Handling Errors ​

Using Type Guards ​

typescript
import { isErr, isOk, unwrap } from '@fizzy-do-mcp/shared';

const result = await client.cards.getByNumber(42);

if (isErr(result)) {
  const error = result.error;
  
  switch (error.code) {
    case 'NOT_FOUND':
      console.log('Card not found');
      break;
    case 'UNAUTHORIZED':
      console.log('Please check your API token');
      break;
    case 'RATE_LIMITED':
      console.log('Too many requests, please wait');
      break;
    default:
      console.log('Error:', error.message);
  }
} else {
  const card = unwrap(result);
  console.log('Found card:', card.title);
}

Using Pattern Matching ​

typescript
import { match } from '@fizzy-do-mcp/shared';

const result = await client.boards.list();

match(result, {
  ok: (boards) => {
    console.log(`Found ${boards.length} boards`);
  },
  err: (error) => {
    console.error(`Failed: ${error.message}`);
  },
});

Unwrapping with Default ​

typescript
import { unwrapOr } from '@fizzy-do-mcp/shared';

const result = await client.cards.list({ board_ids: ['board_1'] });
const cards = unwrapOr(result, []); // Returns empty array on error

HTTP Status Mapping ​

StatusError CodeDescription
401UNAUTHORIZEDInvalid API token
403FORBIDDENAccess denied
404NOT_FOUNDResource not found
422VALIDATION_ERRORInvalid parameters
429RATE_LIMITEDRate limit exceeded
500+SERVER_ERRORServer error

Retry Strategy ​

For rate limiting and network errors, implement exponential backoff:

typescript
async function withRetry<T>(
  fn: () => Promise<Result<T, FizzyError>>,
  maxRetries = 3
): Promise<Result<T, FizzyError>> {
  let lastError: FizzyError | undefined;
  
  for (let i = 0; i < maxRetries; i++) {
    const result = await fn();
    
    if (isOk(result)) {
      return result;
    }
    
    lastError = result.error;
    
    if (lastError.code !== 'RATE_LIMITED' && lastError.code !== 'NETWORK_ERROR') {
      return result; // Don't retry other errors
    }
    
    // Exponential backoff
    await new Promise(resolve => setTimeout(resolve, Math.pow(2, i) * 1000));
  }
  
  return err(lastError!);
}