Teams error 502 Bad Gateway: 502 - bot returned an error / service dependency failure
Last verified against Microsoft Learn - Status codes from bot conversational APIs
Failed to send activity: bot returned an errorWhat error 502 Bad Gateway means
502 wears two hats in the Bot Framework, and telling them apart is the whole diagnosis. Hat one: the Connector's own 502. The Teams status table lists 502 as code ServiceError, "Service dependency issue," retry Yes with exponential backoff - a transient fault between Microsoft services while delivering your outbound call. If your send failed with 502, back off and retry; the rate-limit guide names 502 among the codes that "must also be retried."
Hat two - the one that usually brings people here: YOUR endpoint failed. When a channel delivers an activity to your messaging endpoint and your code times out, throws, or returns 5xx, the channel reports it as a 502. The Direct Line reference documents this precisely: "502 - The bot is unavailable or returned an error. This is a common error code," with the canonical body {"error":{"code":"BotRejectedActivity","message":"Failed to send activity: bot returned an error"}}. That is the error you see while testing in Web Chat or the Emulator when the bot's own code is broken.
The cruelty of hat two is the asymmetry between what the user sees and what the log shows. In client surfaces that surface errors (Web Chat, Emulator) you get a generic could-not-send indication; in Teams itself a failed reply is mostly silence - the user's message posts, nothing comes back. Meanwhile the truth (the stack trace) is only in your endpoint's logs or Application Insights. Debug the bot, not the gateway: Microsoft's troubleshoot-500 guide (enable Application Insights, query exceptions, check the adapter's error handler) is the documented route, and the endpoint-side checklist is causes 4 and 8 of Teams bot not responding.
What it looks like
HTTP/1.1 502 Bad Gateway
{
"error": {
"code": "BotRejectedActivity",
"message": "Failed to send activity: bot returned an error"
}
}Why it happens
- Your endpoint threw an unhandled exception processing the inbound activity (hat two).
- Your endpoint took too long to answer - a slow model call, database, or cold start - and the channel gave up.
- The messaging endpoint URL points at a dead deployment, wrong path, or a host with an invalid TLS chain.
- Auth misconfiguration inside your adapter rejects the inbound request, surfacing upstream as a bot error.
- A transient dependency fault inside Microsoft's own services (hat one).
How to fix Teams error 502 Bad Gateway
- 1Decide which hat: 502 on YOUR outbound send call = Connector dependency issue, retry with exponential backoff; 502 reported by a client channel about your bot = your endpoint failed.
- 2For endpoint failures, open Application Insights and query exceptions ordered by timestamp, correlating by operation_Id, per the troubleshoot-500 guide.
- 3Implement the adapter-level error handler (OnTurnError / onTurnError) so exceptions are logged with stack traces instead of vanishing.
- 4curl -X POST your messaging endpoint: a fast 401 means auth is alive; a hang or 5xx reproduces the failure locally.
- 5Fix cold-start and slow-dependency paths: acknowledge the activity quickly and do heavy work asynchronously.
- 6Retest end to end in Teams, not just the Emulator - auth is disabled locally and enabled in production.
How to stop it recurring
Make your endpoint boring: answer every activity fast, push slow work to a queue, and never let an exception escape the adapter unlogged. Wire health checks and alerting to the endpoint itself, because Teams will not tell your users anything useful when it fails. Keep Application Insights on from day one - the difference between a five-minute and five-hour 502 investigation is whether the telemetry already exists. Endpoint reachability testing is covered step by step in the webhook debugging guide.
Official reference: Microsoft Learn - Status codes from bot conversational APIs. See all Teams error codes or the Teams limits and quotas.
Related codes
- 504 Gateway Timeout: 504 - gateway timeoutGateway Timeout.
- 503 Service Unavailable: 503 - service temporarily unavailableService is unavailable.
- 500 ServiceError: 500 - internal server error at the Connector*various
- Unable to reach the app: "Unable to reach the app" - invoke response timed outUnable to reach the app
- 401 Unauthorized (invalid app ID / password): Invalid Microsoft App ID or passwordAADSTS7000215: Invalid client secret provided.
Error 502 Bad Gateway - quick answers
What does Teams error 502 Bad Gateway mean?
502 wears two hats in the Bot Framework, and telling them apart is the whole diagnosis. Hat one: the Connector's own 502. The Teams status table lists 502 as code ServiceError , "Service dependency issue," retry Yes with exponential backoff - a transient fault between Microsoft services while delivering your outbound call.
How do I fix Teams error 502 Bad Gateway?
1. Decide which hat: 502 on YOUR outbound send call = Connector dependency issue, retry with exponential backoff; 502 reported by a client channel about your bot = your endpoint failed. 2. For endpoint failures, open Application Insights and query exceptions ordered by timestamp, correlating by operation_Id, per the troubleshoot-500 guide. 3. Implement the adapter-level error handler (OnTurnError / onTurnError) so exceptions are logged with stack traces instead of…
Can I retry after error 502 Bad Gateway?
Yes - this is a retryable condition. Back off (start around one second and double on each attempt, with jitter) and watch for a retry-after hint from the platform before resending.
Stop debugging Teams by hand
Connect the channel through Conferbot: tokens, webhooks and retries are handled, failures show as readable status.