Make use of errors.NotFound

This commit is contained in:
Juan Cruz Viotti 2014-11-24 14:48:16 -04:00
parent 86548fc3d2
commit 927b7bc0eb
4 changed files with 7 additions and 5 deletions

View File

@ -12,7 +12,7 @@ isSystemVariable = (environmentVariable) ->
SYSTEM_VAR_REGEX.test(environmentVariable.name) SYSTEM_VAR_REGEX.test(environmentVariable.name)
exports.list = authHooks.failIfNotLoggedIn (program) -> exports.list = authHooks.failIfNotLoggedIn (program) ->
applicationId = program.parent.application applicationId = program.parent?.application
if not applicationId? if not applicationId?
errors.handle(new Error('You have to specify an application')) errors.handle(new Error('You have to specify an application'))

View File

@ -27,7 +27,7 @@ exports.info = authHooks.failIfNotLoggedIn (id) ->
errors.handle(error) if error? errors.handle(error) if error?
key = _.findWhere(keys, { id }) key = _.findWhere(keys, { id })
if not key? if not key?
errors.handle(new Error("Key #{id} doesn't exists")) errors.handle(new errors.NotFound("key #{id}"))
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' ]))

View File

@ -1,5 +1,6 @@
Promise = require('bluebird') Promise = require('bluebird')
canvas = require('./_canvas') canvas = require('./_canvas')
errors = require('../errors/errors')
exports.getAll = -> exports.getAll = ->
return canvas.get return canvas.get
@ -15,7 +16,7 @@ exports.get = (id) ->
.then (application) -> .then (application) ->
if not application? if not application?
return Promise.reject(new Error('Not found')) return Promise.reject(new errors.NotFound("application #{id}"))
return application return application
@ -30,7 +31,7 @@ exports.create = (name, deviceType) ->
id = res?.id id = res?.id
if not id? if not id?
return Promise.reject(new Error('Could not find created application id.')) return Promise.reject(new errors.NotFound('created application id'))
return id return id

View File

@ -1,5 +1,6 @@
Promise = require('bluebird') Promise = require('bluebird')
canvas = require('./_canvas') canvas = require('./_canvas')
errors = require('../errors/errors')
exports.getAll = (applicationId) -> exports.getAll = (applicationId) ->
return canvas.get return canvas.get
@ -11,7 +12,7 @@ exports.getAll = (applicationId) ->
.then (environmentVariables) -> .then (environmentVariables) ->
if not environmentVariables? if not environmentVariables?
return Promise.reject(new Error('Not found')) return Promise.reject(new errors.NotFound('environment variables'))
return environmentVariables return environmentVariables
exports.remove = (id) -> exports.remove = (id) ->