From ca834fa61aaccfbd72aea9cfdeb5b992e3134d1b Mon Sep 17 00:00:00 2001
From: Rhys Arkins <rhys@arkins.net>
Date: Thu, 11 Mar 2021 15:51:48 +0100
Subject: [PATCH] fix(github): Propagate PR already exists up (#9085)

---
 lib/util/http/github.spec.ts | 8 ++++++++
 lib/util/http/github.ts      | 6 ++++++
 2 files changed, 14 insertions(+)

diff --git a/lib/util/http/github.spec.ts b/lib/util/http/github.spec.ts
index 26686ccc97..c7868c8f93 100644
--- a/lib/util/http/github.spec.ts
+++ b/lib/util/http/github.spec.ts
@@ -187,6 +187,14 @@ describe(getName(__filename), () => {
           'Review cannot be requested from pull request author.'
         );
       });
+      it('should throw original error when pull requests aleady existed', async () => {
+        await expect(
+          fail(422, {
+            message: 'Validation error',
+            errors: [{ message: 'A pull request already exists' }],
+          })
+        ).rejects.toThrow('Validation error');
+      });
       it('should throw original error of unknown type', async () => {
         await expect(
           fail(418, {
diff --git a/lib/util/http/github.ts b/lib/util/http/github.ts
index d2424f8d06..b1095ab054 100644
--- a/lib/util/http/github.ts
+++ b/lib/util/http/github.ts
@@ -111,6 +111,12 @@ function handleGotError(
     } else if (err.body?.errors?.find((e: any) => e.code === 'invalid')) {
       logger.debug({ err }, 'Received invalid response - aborting');
       throw new Error(REPOSITORY_CHANGED);
+    } else if (
+      err.body?.errors?.find((e: any) =>
+        e.message?.startsWith('A pull request already exists')
+      )
+    ) {
+      throw err;
     }
     logger.debug({ err }, '422 Error thrown from GitHub');
     throw new ExternalHostError(err, PLATFORM_TYPE_GITHUB);
-- 
GitLab