Last active
May 12, 2022 15:03
-
-
Save andyhite/7e4252434907012ce310eef3d6b97d2e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
router.get("/orders/:id", (req, res) => { | |
const { sourceCode } = req.query; | |
try { | |
const order = await getOrderById(req.params.id); | |
res.status(200).json(order); | |
} catch (err) { | |
if (axios.isAxiosError(err)) { | |
if (err.code === 404 && sourceCode) { | |
await refreshOrderSource(sourceCode); | |
const order = await getOrderById(req.params.id); | |
res.status(200).json(order); | |
} | |
throw err; // whatever we do with generic errors | |
} | |
throw err; | |
} | |
}); | |
// in the api lib | |
const refreshOrderSource = async (sourceCode: string, synchronous: true) => { | |
if (synchronous) { | |
// logic for polling and waiting for the order source to be refreshed goes here | |
// probably calling `refreshOrderSource` recursively with synchronous = false in each loop | |
// until it returns from this function when the order is done refreshing | |
} | |
// logic for initiating the refresh goes here | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment