# 处理失败的 Webhook 交付

GitHub 不会自动重新传送失败的 Webhook 交付，但你可以手动或通过编写代码来处理失败的交付。

## 关于 Webhook 交付失败

Webhook 交付可能因多种原因而失败。 例如，如果服务器关闭或花费的时间超过 30 秒进行响应， GitHub 则会将传递记录为失败。

GitHub 不会自动重新传送失败的交付。

## 处理交付失败

可以手动重新交付失败的交付。 有关详细信息，请参阅“[重新传递 Webhook](/zh/enterprise-server@3.22/webhooks/testing-and-troubleshooting-webhooks/redelivering-webhooks)”。

也可以编写脚本来检查失败的交付并尝试重新交付任何失败的交付。 脚本应按计划运行并执行以下操作：

1. 使用 GitHub REST API 获取有关自你的脚本上次运行以来曾尝试进行的任何 webhook 传递的数据。 有关详细信息，请参阅“[存储库 Webhook 的 REST API 终结点](/zh/enterprise-server@3.22/rest/repos/webhooks#list-deliveries-for-a-repository-webhook)”、“[用于组织 Webhooks 的 REST API 接口节点](/zh/enterprise-server@3.22/rest/orgs/webhooks#list-deliveries-for-an-organization-webhook)”和“[Webhooks 的 GitHub App REST API 终结点](/zh/enterprise-server@3.22/rest/apps/webhooks#list-deliveries-for-an-app-webhook)”。

没有 API 终结点可用于获取有关全局 Webhook 交付的数据。

1. 查看提取的数据，检查是否有失败的交付。 失败交付的数据的 `status` 值不是 `OK`。
2. GitHub使用 REST API 重新传送失败的任何交付。 有关详细信息，请参阅“[存储库 Webhook 的 REST API 终结点](/zh/enterprise-server@3.22/rest/repos/webhooks#redeliver-a-delivery-for-a-repository-webhook)”、“[用于组织 Webhooks 的 REST API 接口节点](/zh/enterprise-server@3.22/rest/orgs/webhooks#redeliver-a-delivery-for-an-organization-webhook)”和“[Webhooks 的 GitHub App REST API 终结点](/zh/enterprise-server@3.22/rest/apps/webhooks#redeliver-a-delivery-for-an-app-webhook)”。

有关示例脚本，请参阅：

* [自动重新传送存储库 Webhook 的失败交付](/zh/enterprise-server@3.22/webhooks/using-webhooks/automatically-redelivering-failed-deliveries-for-a-repository-webhook)
* [自动重新传送组织 Webhook 的失败交付](/zh/enterprise-server@3.22/webhooks/using-webhooks/automatically-redelivering-failed-deliveries-for-an-organization-webhook)
* [自动重新传送 GitHub App Webhook 的失败交付](/zh/enterprise-server@3.22/webhooks/using-webhooks/automatically-redelivering-failed-deliveries-for-a-github-app-webhook)

如果 Webhook 交付反复失败，则应调查原因。 每个失败交付都要给出失败的原因。 有关详细信息，请参阅“[Webhook 疑难解答](/zh/enterprise-server@3.22/webhooks/testing-and-troubleshooting-webhooks/troubleshooting-webhooks)”。