From f112ea1aa9c419bc4ec15859c41ef75bed05e696 Mon Sep 17 00:00:00 2001 From: Gabriel Ratcliff Date: Tue, 16 Jul 2019 11:33:27 -0700 Subject: [PATCH] Fix review comments: 1. Error handling for dup creation 2. Help Params for versions 3. Copy --- lib/versions/create.js | 22 +++++++++++++--------- lib/versions/delete.js | 1 + lib/versions/index.js | 1 + lib/versions/versionId.js | 2 +- 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/lib/versions/create.js b/lib/versions/create.js index 943decded..9b19d2ee5 100644 --- a/lib/versions/create.js +++ b/lib/versions/create.js @@ -44,13 +44,17 @@ exports.run = async function({ opts }) { auth: { user: key }, }; - return request.post(`${config.host}/api/v1/version`, options).catch(err => { - let errorDesc; - try { - errorDesc = JSON.parse(err.error).description; - } catch (e) { - errorDesc = 'Failed to create a new version using your specified parameters.'; - } - return Promise.reject(new Error(errorDesc)); - }); + return request + .post(`${config.host}/api/v1/version`, options) + .then(() => Promise.resolve(`Version ${version} created successfully`)) + .catch(err => { + let errorDesc; + try { + errorDesc = + typeof err.error === 'string' ? JSON.parse(err.error).description : err.error.description; + } catch (e) { + errorDesc = 'Failed to create a new version using your specified parameters.'; + } + return Promise.reject(new Error(errorDesc)); + }); }; diff --git a/lib/versions/delete.js b/lib/versions/delete.js index f363bbec4..0888c9bba 100644 --- a/lib/versions/delete.js +++ b/lib/versions/delete.js @@ -23,6 +23,7 @@ exports.run = async function({ opts }) { .delete(`${config.host}/api/v1/version/${version}`, { auth: { user: key }, }) + .then(() => Promise.resolve(`Version ${version} deleted successfully`)) .catch(err => { let errorDesc; try { diff --git a/lib/versions/index.js b/lib/versions/index.js index adacb8904..19ef67ea0 100644 --- a/lib/versions/index.js +++ b/lib/versions/index.js @@ -4,6 +4,7 @@ const config = require('config'); exports.desc = 'List versions available in your project'; exports.category = 'services'; exports.weight = 3; +exports.action = 'versions'; exports.run = function({ opts }) { const { key } = opts; diff --git a/lib/versions/versionId.js b/lib/versions/versionId.js index 5882bac18..4371f9b46 100644 --- a/lib/versions/versionId.js +++ b/lib/versions/versionId.js @@ -1,7 +1,7 @@ const request = require('request-promise-native'); const config = require('config'); -exports.desc = 'List versions available in your project'; +exports.desc = 'Get a specific version from your project'; exports.category = 'services'; exports.weight = 4; exports.action = 'versions:versionId';