Skip to content

Commit

Permalink
🎉 don't throw an error when registering an already-registered gdoc
Browse files Browse the repository at this point in the history
  • Loading branch information
ikesau committed Dec 8, 2023
1 parent 24e11f6 commit 806c851
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion adminSiteServer/apiRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2494,7 +2494,21 @@ apiRouter.put("/gdocs/:id", async (req, res) => {
if (isEmpty(nextGdocJSON)) {
const newGdoc = new GdocPost(id)
// this will fail if the gdoc already exists, as opposed to a call to newGdoc.save()
await dataSource.getRepository(GdocPost).insert(newGdoc)
try {
await dataSource.getRepository(GdocPost).insert(newGdoc)
} catch (e) {
if (
typeof e === "object" &&
e !== null &&
"code" in e &&
e.code === "ER_DUP_ENTRY"
) {
const preexistingGdoc = dataSource
.getRepository(GdocPost)
.findBy({ id: id })
return preexistingGdoc
}
}

const publishedExplorersBySlug =
await explorerAdminServer.getAllPublishedExplorersBySlugCached()
Expand Down

0 comments on commit 806c851

Please sign in to comment.