01 · Before and afterThe pattern
await api.delete(old.id);
try {
await api.create(next);
} catch (err) {
try { await api.create(old); } // restore from the copy we read first
catch { throw new Error(`Lost ${old.type} ${old.name} -> ${old.target}; recreate it`); }
throw err; // the original reason still wins
}
try { await api.publish(zone); }
catch { throw new Error("Saved, not yet published; do not redo it"); }02 · Run it on your appThe check
When step two of a two-step change to an external system fails, does your app tell the user what state step one left?
If the honest answer is no or not sure, this is worth a look before it reaches production.