diff --git a/lib/httpd.js b/lib/httpd.js index 4856c22..9a4eeff 100644 --- a/lib/httpd.js +++ b/lib/httpd.js @@ -277,6 +277,10 @@ module.exports.create = function (cli, engine/*, dnsd*/) { res.send({ error: { message: err.message } }); return; } + if (!record) { + res.send({ error: { message: "no record with id '" + id + "' found" } }); + return; + } if ('SOA' === record.type) { // TODO be strict about what can be edited diff --git a/lib/public/js/app.js b/lib/public/js/app.js index 3c6d1a2..83d0417 100644 --- a/lib/public/js/app.js +++ b/lib/public/js/app.js @@ -397,16 +397,6 @@ var id = $qs('.js-record-id', $pel).value; var existingRecord = cache.recordsMap[id]; - delete cache.recordsMap[id]; - cache.records.some(function (r, i) { - if (r === existingRecord) { - cache.records.splice(i, 1); - return true; - } - }); - - renderRecords(); - return window.fetch( '/api/records/' + id , { method: 'DELETE' @@ -422,6 +412,15 @@ window.alert(data.error.message); return; } + delete cache.recordsMap[id]; + cache.records.some(function (r, i) { + if (r === existingRecord) { + cache.records.splice(i, 1); + return true; + } + }); + + renderRecords(); console.log('result:', data); }); });