mirror of
https://github.com/balena-io/balena-cli.git
synced 2025-02-22 10:11:01 +00:00
Make use of errors.handle() everywhere
This commit is contained in:
parent
90cb463390
commit
5549a2bd9e
@ -2,6 +2,7 @@ _ = require('lodash')
|
|||||||
async = require('async')
|
async = require('async')
|
||||||
device = require('../device/device')
|
device = require('../device/device')
|
||||||
table = require('../table/table')
|
table = require('../table/table')
|
||||||
|
errors = require('../errors/errors')
|
||||||
log = require('../log/log')
|
log = require('../log/log')
|
||||||
server = require('../server/server')
|
server = require('../server/server')
|
||||||
widgets = require('../widgets/widgets')
|
widgets = require('../widgets/widgets')
|
||||||
@ -32,8 +33,7 @@ exports.create = authHooks.failIfNotLoggedIn (name, program) ->
|
|||||||
return callback()
|
return callback()
|
||||||
.catch(callback)
|
.catch(callback)
|
||||||
|
|
||||||
], (error) ->
|
], errors.handle
|
||||||
throw error if error?
|
|
||||||
|
|
||||||
exports.list = authHooks.failIfNotLoggedIn ->
|
exports.list = authHooks.failIfNotLoggedIn ->
|
||||||
applicationModel.getAll().then (applications) ->
|
applicationModel.getAll().then (applications) ->
|
||||||
@ -47,8 +47,7 @@ exports.list = authHooks.failIfNotLoggedIn ->
|
|||||||
return application
|
return application
|
||||||
, [ 'ID', 'Name', 'Device Type', 'Online Devices', 'All Devices' ]
|
, [ 'ID', 'Name', 'Device Type', 'Online Devices', 'All Devices' ]
|
||||||
|
|
||||||
.catch (error) ->
|
.catch(errors.handle)
|
||||||
throw error
|
|
||||||
|
|
||||||
exports.info = authHooks.failIfNotLoggedIn (id) ->
|
exports.info = authHooks.failIfNotLoggedIn (id) ->
|
||||||
applicationModel.get(id).then (application) ->
|
applicationModel.get(id).then (application) ->
|
||||||
@ -59,19 +58,16 @@ exports.info = authHooks.failIfNotLoggedIn (id) ->
|
|||||||
return application
|
return application
|
||||||
, [ 'ID', 'Name', 'Device Type', 'Git Repository', 'Commit' ]
|
, [ 'ID', 'Name', 'Device Type', 'Git Repository', 'Commit' ]
|
||||||
|
|
||||||
.catch (error) ->
|
.catch(errors.handle)
|
||||||
throw error
|
|
||||||
|
|
||||||
exports.restart = authHooks.failIfNotLoggedIn (id) ->
|
exports.restart = authHooks.failIfNotLoggedIn (id) ->
|
||||||
|
|
||||||
# TODO: Move this URL to config
|
# TODO: Move this URL to config
|
||||||
server.post "/application/#{id}/restart", (error) ->
|
server.post("/application/#{id}/restart", errors.handle)
|
||||||
throw error if error?
|
|
||||||
|
|
||||||
exports.remove = authHooks.failIfNotLoggedIn (id, program) ->
|
exports.remove = authHooks.failIfNotLoggedIn (id, program) ->
|
||||||
patterns.remove 'application', program.parent.yes, (callback) ->
|
patterns.remove 'application', program.parent.yes, (callback) ->
|
||||||
applicationModel.remove(id).then ->
|
applicationModel.remove(id).then ->
|
||||||
return callback()
|
return callback()
|
||||||
.catch(callback)
|
.catch(callback)
|
||||||
, (error) ->
|
, errors.handle
|
||||||
throw error if error?
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
open = require('open')
|
open = require('open')
|
||||||
async = require('async')
|
async = require('async')
|
||||||
auth = require('../auth/auth')
|
auth = require('../auth/auth')
|
||||||
|
errors = require('../errors/errors')
|
||||||
authHooks = require('../hooks/auth')
|
authHooks = require('../hooks/auth')
|
||||||
widgets = require('../widgets/widgets')
|
widgets = require('../widgets/widgets')
|
||||||
config = require('../config')
|
config = require('../config')
|
||||||
@ -17,8 +18,7 @@ exports.login = (credentials) ->
|
|||||||
(credentials, callback) ->
|
(credentials, callback) ->
|
||||||
auth.login(credentials, callback)
|
auth.login(credentials, callback)
|
||||||
|
|
||||||
], (error) ->
|
], errors.handle
|
||||||
throw error if error?
|
|
||||||
|
|
||||||
exports.logout = authHooks.failIfNotLoggedIn ->
|
exports.logout = authHooks.failIfNotLoggedIn ->
|
||||||
auth.logout()
|
auth.logout()
|
||||||
|
@ -2,6 +2,7 @@ deviceModel = require('../models/device')
|
|||||||
getDeviceDisplayName = require('../device/device').getDisplayName
|
getDeviceDisplayName = require('../device/device').getDisplayName
|
||||||
log = require('../log/log')
|
log = require('../log/log')
|
||||||
table = require('../table/table')
|
table = require('../table/table')
|
||||||
|
errors = require('../errors/errors')
|
||||||
server = require('../server/server')
|
server = require('../server/server')
|
||||||
widgets = require('../widgets/widgets')
|
widgets = require('../widgets/widgets')
|
||||||
patterns = require('../patterns/patterns')
|
patterns = require('../patterns/patterns')
|
||||||
@ -21,17 +22,14 @@ exports.list = authHooks.failIfNotLoggedIn (applicationId) ->
|
|||||||
return device
|
return device
|
||||||
, [ 'ID', 'Name', 'Device Type', 'Is Online', 'IP Address', 'Application', 'Status', 'Last Seen' ]
|
, [ 'ID', 'Name', 'Device Type', 'Is Online', 'IP Address', 'Application', 'Status', 'Last Seen' ]
|
||||||
|
|
||||||
.catch (error) ->
|
.catch(errors.handle)
|
||||||
throw error
|
|
||||||
|
|
||||||
exports.remove = authHooks.failIfNotLoggedIn (id, program) ->
|
exports.remove = authHooks.failIfNotLoggedIn (id, program) ->
|
||||||
patterns.remove 'device', program.parent.yes, (callback) ->
|
patterns.remove 'device', program.parent.yes, (callback) ->
|
||||||
deviceModel.remove(id).then ->
|
deviceModel.remove(id).then ->
|
||||||
return callback()
|
return callback()
|
||||||
.catch(callback)
|
.catch(callback)
|
||||||
, (error) ->
|
, errors.handle
|
||||||
throw error if error?
|
|
||||||
|
|
||||||
exports.identify = authHooks.failIfNotLoggedIn (uuid) ->
|
exports.identify = authHooks.failIfNotLoggedIn (uuid) ->
|
||||||
server.post config.urls.identify, { uuid }, (error) ->
|
server.post(config.urls.identify, { uuid }, errors.handle)
|
||||||
throw error if error?
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
_ = require('lodash')
|
_ = require('lodash')
|
||||||
table = require('../table/table')
|
table = require('../table/table')
|
||||||
|
errors = require('../errors/errors')
|
||||||
patterns = require('../patterns/patterns')
|
patterns = require('../patterns/patterns')
|
||||||
log = require('../log/log')
|
log = require('../log/log')
|
||||||
environemtVariablesModel = require('../models/environment-variables')
|
environemtVariablesModel = require('../models/environment-variables')
|
||||||
@ -14,7 +15,7 @@ exports.list = authHooks.failIfNotLoggedIn (program) ->
|
|||||||
applicationId = program.parent.application
|
applicationId = program.parent.application
|
||||||
|
|
||||||
if not applicationId?
|
if not applicationId?
|
||||||
throw new Error('You have to specify an application')
|
errors.handle(new Error('You have to specify an application'))
|
||||||
|
|
||||||
environemtVariablesModel.getAll(applicationId).then (environmentVariables) ->
|
environemtVariablesModel.getAll(applicationId).then (environmentVariables) ->
|
||||||
|
|
||||||
@ -22,13 +23,11 @@ exports.list = authHooks.failIfNotLoggedIn (program) ->
|
|||||||
environmentVariables = _.reject(environmentVariables, isSystemVariable)
|
environmentVariables = _.reject(environmentVariables, isSystemVariable)
|
||||||
|
|
||||||
log.out(table.horizontal(environmentVariables))
|
log.out(table.horizontal(environmentVariables))
|
||||||
.catch (error) ->
|
.catch(errors.handle)
|
||||||
throw error
|
|
||||||
|
|
||||||
exports.remove = authHooks.failIfNotLoggedIn (id, program) ->
|
exports.remove = authHooks.failIfNotLoggedIn (id, program) ->
|
||||||
patterns.remove 'environment variable', program.parent.yes, (callback) ->
|
patterns.remove 'environment variable', program.parent.yes, (callback) ->
|
||||||
environemtVariablesModel.remove(id).then ->
|
environemtVariablesModel.remove(id).then ->
|
||||||
return callback()
|
return callback()
|
||||||
.catch(callback)
|
.catch(callback)
|
||||||
, (error) ->
|
, errors.handle
|
||||||
throw error if error?
|
|
||||||
|
@ -5,12 +5,13 @@ log = require('../log/log')
|
|||||||
patterns = require('../patterns/patterns')
|
patterns = require('../patterns/patterns')
|
||||||
table = require('../table/table')
|
table = require('../table/table')
|
||||||
helpers = require('../helpers/helpers')
|
helpers = require('../helpers/helpers')
|
||||||
|
errors = require('../errors/errors')
|
||||||
keyModel = require('../models/key')
|
keyModel = require('../models/key')
|
||||||
config = require('../config')
|
config = require('../config')
|
||||||
|
|
||||||
exports.list = authHooks.failIfNotLoggedIn ->
|
exports.list = authHooks.failIfNotLoggedIn ->
|
||||||
server.get config.urls.keys, (error, response, keys) ->
|
server.get config.urls.keys, (error, response, keys) ->
|
||||||
throw error if error?
|
errors.handle(error) if error?
|
||||||
log.out table.horizontal keys, (key) ->
|
log.out table.horizontal keys, (key) ->
|
||||||
delete key.public_key
|
delete key.public_key
|
||||||
return key
|
return key
|
||||||
@ -23,10 +24,10 @@ exports.info = authHooks.failIfNotLoggedIn (id) ->
|
|||||||
# As a workaround, we request all of them, and filter
|
# As a workaround, we request all of them, and filter
|
||||||
# the one we need. Fix once we have a better way.
|
# the one we need. Fix once we have a better way.
|
||||||
server.get config.urls.keys, (error, response, keys) ->
|
server.get config.urls.keys, (error, response, keys) ->
|
||||||
throw error if error?
|
errors.handle(error) if error?
|
||||||
key = _.findWhere(keys, { id })
|
key = _.findWhere(keys, { id })
|
||||||
if not key?
|
if not key?
|
||||||
throw new Error("Key #{id} doesn't exists")
|
errors.handle(new Error("Key #{id} doesn't exists"))
|
||||||
|
|
||||||
key.public_key = '\n' + helpers.formatLongString(key.public_key, config.sshKeyWidth)
|
key.public_key = '\n' + helpers.formatLongString(key.public_key, config.sshKeyWidth)
|
||||||
log.out(table.vertical(key, _.identity, [ 'ID', 'Title', 'Public Key' ]))
|
log.out(table.vertical(key, _.identity, [ 'ID', 'Title', 'Public Key' ]))
|
||||||
@ -34,5 +35,4 @@ exports.info = authHooks.failIfNotLoggedIn (id) ->
|
|||||||
exports.remove = authHooks.failIfNotLoggedIn (id, program) ->
|
exports.remove = authHooks.failIfNotLoggedIn (id, program) ->
|
||||||
patterns.remove 'key', program.parent.yes, (callback) ->
|
patterns.remove 'key', program.parent.yes, (callback) ->
|
||||||
server.delete("/user/keys/#{id}", callback)
|
server.delete("/user/keys/#{id}", callback)
|
||||||
, (error) ->
|
, errors.handle
|
||||||
throw error if error?
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user