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