Avoid race conditions from writing res status twi

This commit is contained in:
Daniel Lugo 2021-08-18 16:12:52 -04:00
parent ea22f3bab9
commit 37943b145c

View file

@ -2463,14 +2463,15 @@ module.exports = async (
const epubForDecryption = req.header(EPUB_FOR_DECRYPT_HEADER) const epubForDecryption = req.header(EPUB_FOR_DECRYPT_HEADER)
const { path } = req.params const { path } = req.params
logger.info(`gun otheruser ONCE: ${path}`) logger.info(`gun otheruser ONCE: ${path}`)
res.status(200).json({ const data = await handleGunFetch({
data: await handleGunFetch({
path, path,
startFromUserGraph: true, startFromUserGraph: true,
type: 'once', type: 'once',
publicKeyForDecryption, publicKeyForDecryption,
epubForDecryption epubForDecryption
}) })
res.status(200).json({
data
}) })
} catch (e) { } catch (e) {
logger.error(e) logger.error(e)
@ -2486,14 +2487,15 @@ module.exports = async (
const epubForDecryption = req.header(EPUB_FOR_DECRYPT_HEADER) const epubForDecryption = req.header(EPUB_FOR_DECRYPT_HEADER)
const { path } = req.params const { path } = req.params
logger.info(`gun self user LOAD: ${path}`) logger.info(`gun self user LOAD: ${path}`)
res.status(200).json({ const data = await handleGunFetch({
data: await handleGunFetch({
path, path,
startFromUserGraph: true, startFromUserGraph: true,
type: 'load', type: 'load',
publicKeyForDecryption, publicKeyForDecryption,
epubForDecryption epubForDecryption
}) })
res.status(200).json({
data
}) })
} catch (e) { } catch (e) {
logger.error(e) logger.error(e)
@ -2524,9 +2526,7 @@ module.exports = async (
}) })
return return
} }
try { const data = await handleGunFetch({
res.status(200).json({
data: await handleGunFetch({
path, path,
startFromUserGraph: false, startFromUserGraph: false,
type, type,
@ -2534,6 +2534,9 @@ module.exports = async (
publicKeyForDecryption, publicKeyForDecryption,
epubForDecryption epubForDecryption
}) })
try {
res.status(200).json({
data
}) })
} catch (err) { } catch (err) {
res res