Skip to content

Commit

Permalink
Fix to prevent deleting all records (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielpigott committed Oct 1, 2020
1 parent 3a7b912 commit 9047025
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,11 @@ function CloudflareCli(options) {
let formatter = new formatters.MessageFormatter();
//Log error from server if provided in the response
if (error.response && error.response.data.errors) {
formatter.format(['Error response received: ' + error.response.data.errors[0].message]);
formatter.format([`Error response received: ${error.response.data.errors[0].message}`]);
} else if (error.message) {
formatter.format([`Error when communicating with api: ${error.message}`]);
} else {
formatter.format(['Error when communicating with api: ' + error.message]);
formatter.format([`Error: ${error}`]);
}
process.exit(1);
});
Expand Down Expand Up @@ -304,6 +306,9 @@ function CloudflareCli(options) {
*/
function removeRecord(options) {
let query = getQueryParams(options, ['name', 'content', 'type', 'query']);
if (query.name === undefined) {
return Promise.reject('name not provided');
}
return find(options.domain, query).then(function (response) {
let records = response.data.result;
if (records.length === 0) {
Expand Down Expand Up @@ -557,7 +562,7 @@ function CloudflareCli(options) {
* @param allowed
*/
function getQueryParams(options, allowed) {
return _(options).pick(allowed).omitBy(_.isUndefined).value();
return _(options).pick(allowed).omitBy(_.isUndefined).mapValues((val) => {return _.toString(val)}).value();
}

/**
Expand Down

0 comments on commit 9047025

Please sign in to comment.