---
title: "BAD_GATEWAY"
description: "What triggers a BAD_GATEWAY error (HTTP 502) when the upstream EHR system is unreachable."
canonical_url: "https://docs.leyr.io/api/error-handling/bad_gateway"
---
# BAD_GATEWAY

> What triggers a BAD_GATEWAY error (HTTP 502) when the upstream EHR system is unreachable.

## Summary

Corresponds to a standard `502 Bad Gateway` HTTP response status

> Leyr received an invalid response from the upstream EHR system, or could not reach it at all. Most likely a connection error on the EHR side.

## Example Response

```json
{
    "code": "BAD_GATEWAY",
    "type": "https://docs.leyr.io/api/error-handling/bad_gateway",
    "title": "Bad Gateway",
    "status": 502,
    "detail": "Bad gateway. Most likely connection error. Try again or contact us if the issue persists.",
    "instance": "36b5909e-4391-4520-b303-84cbb80c4264"
}
```

## Common Causes

- The EHR system is down or temporarily unreachable
- A network connectivity failure between Leyr and the EHR
- The EHR returned a malformed or unexpected response

## Resolution Steps

1. Retry your request after a brief delay, as the issue is often temporary. Progressive retries (e.g. 1s, 5s, 15s, 30s, 1m) are a good option.
2. Check whether the EHR system itself is available - for example, whether the clinic's EHR instance is undergoing maintenance.
3. If the issue persists beyond several retry attempts, contact our support team at [contact@leyr.io](mailto:contact@leyr.io) with the `instance` ID from the error response.


## Sitemap

See the full [sitemap](https://docs.leyr.io/sitemap.md) for all pages.
