---
title: "Error Handling | Micdrop"
description: "Handle server-side errors gracefully with comprehensive error management and recovery strategies."
url: "https://micdrop.dev/docs/server/error-handling"
---

*   [Getting Started](/docs/getting-started)
*   [Client (Browser)](/docs/client)
    
    *   [Installation](/docs/client/installation)
    *   [React Hooks](/docs/client/react-hooks)
    *   [Start/Stop Call](/docs/client/start-stop-call)
    *   [Pause/Resume Call](/docs/client/pause-resume-call)
    *   [Mute/Unmute Call](/docs/client/mute-unmute-call)
    *   [Call State](/docs/client/call-state)
    *   [Display Conversation Messages](/docs/client/display-conversation-messages)
    *   [Handling Tool Calls](/docs/client/handling-tool-calls)
    *   [Device Management](/docs/client/devices-management)
    *   [Voice Activity Detection (VAD)](/docs/client/vad)
    *   [Error Handling](/docs/client/error-handling)
    *   Utility Classes
        
        *   [Mic](/docs/client/utility-classes/mic)
        *   [MicdropClient](/docs/client/utility-classes/micdrop-client)
        *   [MicRecorder](/docs/client/utility-classes/mic-recorder)
        *   [Speaker](/docs/client/utility-classes/speaker)
        
    
*   [Server (Node.js)](/docs/server)
    
    *   [Installation](/docs/server/installation)
    *   [With Fastify](/docs/server/with-fastify)
    *   [With NestJS](/docs/server/with-nestjs)
    *   [Auth and Parameters](/docs/server/auth-and-parameters)
    *   [First Message](/docs/server/first-message)
    *   [Save Messages](/docs/server/save-messages)
    *   [Resume a Conversation](/docs/server/resume-conversation)
    *   [Recording Audio](/docs/server/recording-audio)
    *   [Error Handling](/docs/server/error-handling)
    *   [Tools](/docs/server/tools)
    *   [Extract Value from Answer](/docs/server/extract)
    *   [Auto End Call](/docs/server/auto-end-call)
    *   [Semantic Turn Detection](/docs/server/semantic-turn-detection)
    *   [Noise Filtering](/docs/server/noise-filtering)
    *   [Micdrop Protocol](/docs/server/protocol)
    
*   [AI Integrations](/docs/ai-integration)
    
    *   Provided Integrations
        
        *   [AI SDK](/docs/ai-integration/provided-integrations/ai-sdk)
        *   [Cartesia](/docs/ai-integration/provided-integrations/cartesia)
        *   [ElevenLabs](/docs/ai-integration/provided-integrations/elevenlabs)
        *   [Gladia](/docs/ai-integration/provided-integrations/gladia)
        *   [Gradium](/docs/ai-integration/provided-integrations/gradium)
        *   [Mistral](/docs/ai-integration/provided-integrations/mistral)
        *   [OpenAI](/docs/ai-integration/provided-integrations/openai)
        
    *   Custom Integrations
        
        *   [Agent (LLM)](/docs/ai-integration/custom-integrations/custom-agent)
        *   [Speech-to-Text (STT)](/docs/ai-integration/custom-integrations/custom-stt)
        *   [Text-to-Speech (TTS)](/docs/ai-integration/custom-integrations/custom-tts)
        
    *   Fallback Strategies
        
        *   [FallbackAgent](/docs/ai-integration/fallback-strategies/agent-fallback)
        *   [FallbackSTT](/docs/ai-integration/fallback-strategies/stt-fallback)
        *   [FallbackTTS](/docs/ai-integration/fallback-strategies/tts-fallback)
        
    *   [IA Vocale Souveraine 🇫🇷🇪🇺](/docs/ai-integration/sovereign-voice-ai)
    

[Micdrop](/) › [Documentation](/docs/getting-started)

# Error Handling

Handle server-side errors gracefully with comprehensive error management and recovery strategies.

## Basic Error Handling

Use `handleError` utility for consistent error handling:

```
import { MicdropServer, handleError } from '@micdrop/server'
wss.on('connection', async (socket) => {  try {    // Setup AI components    const agent = new OpenaiAgent({      apiKey: process.env.OPENAI_API_KEY,    })
    new MicdropServer(socket, { agent, tts })  } catch (error) {    // Handle setup errors    handleError(socket, error)  }})
```

## Custom Error Types

Create specific error responses:

```
import {  MicdropError,  MicdropErrorCode,  waitForParams,  handleError,} from '@micdrop/server'
wss.on('connection', async (socket) => {  try {    // Validate environment    if (!process.env.OPENAI_API_KEY) {      throw new MicdropError(        MicdropErrorCode.InternalServer,        'OpenAI API key not configured'      )    }
    // Check authentication    const params = await waitForParams(socket, validateParams)    if (!isValidAuth(params.authorization)) {      throw new MicdropError(        MicdropErrorCode.Unauthorized,        'Invalid authorization token'      )    }
    // Setup MicdropServer  } catch (error) {    handleError(socket, error)  }})
```

[Previous← Recording Audio](/docs/server/recording-audio)[NextTools →](/docs/server/tools)

On this page

*   [Basic Error Handling](#basic-error-handling)
*   [Custom Error Types](#custom-error-types)
