gr2m / github-app-webhook-relay

Receive webhooks from a GitHub repository using websockets amended with an installation key for usage with GitHub Apps
ISC License
4 stars 1 forks source link

Handle "Hook already exists on this repository" error #5

Open gr2m opened 1 year ago

gr2m commented 1 year ago
Example error ```js { status: 422, response: { url: 'https://api.github.com/repos/my-owner/my-repo/hooks', status: 422, headers: { // ... }, data: { message: 'Validation Failed', errors: [ { resource: 'Hook', code: 'custom', message: 'Hook already exists on this repository' } ], documentation_url: 'https://docs.github.com/rest/webhooks/repos#create-a-repository-webhook' } }, request: { method: 'POST', url: 'https://api.github.com/repos/hearts-testing/test/hooks', headers: { accept: 'application/vnd.github.v3+json', 'user-agent': '...', authorization: 'token [REDACTED]', 'content-type': 'application/json; charset=utf-8' }, body: '{"name":"cli","events":["issues"],"config":{"content_type":"json","insecure_ssl":"0"}}', request: { hook: [Function: bound bound register] } } } ```

We should instead throw a more helpful error with a link to where the user can delete the token manually. We might even find out more about the created webhook token, and if it was created by the same user, we might consider deleting and re-creating it transparently