Make 404 error handling on deletes more specific

The GCS persistor error handler ignores 404 errors on deletes. However,
the net is too wide cast, and 404 errors coming from the dual-bucket
lifecycle mechanism are also ignored.
This commit is contained in:
Eric Mc Sween 2020-10-15 10:35:52 -04:00
parent 9f28adf96c
commit 0fdfa706f7

View file

@ -200,17 +200,21 @@ module.exports = class GcsPersistor extends AbstractPersistor {
if (this.settings.unlockBeforeDelete) {
await file.setMetadata({ eventBasedHold: false })
}
await file.delete()
try {
await file.delete()
} catch (err) {
// ignore 404s: it's fine if the file doesn't exist.
if (err.code !== 404) {
throw err
}
}
} catch (err) {
const error = PersistorHelper.wrapError(
throw PersistorHelper.wrapError(
err,
'error deleting GCS object',
{ bucketName, key },
WriteError
)
if (!(error instanceof NotFoundError)) {
throw error
}
}
}