2014-11-26 10:32:57 -04:00
|
|
|
_ = require('lodash')
|
2014-11-24 14:00:35 -04:00
|
|
|
TypedError = require('typed-error')
|
|
|
|
log = require('../log/log')
|
|
|
|
|
|
|
|
exports.NotFound = class NotFound extends TypedError
|
2014-11-24 14:41:16 -04:00
|
|
|
constructor: (name) ->
|
2014-11-24 14:00:35 -04:00
|
|
|
@message = "Couldn't find #{name}"
|
2014-11-26 10:32:57 -04:00
|
|
|
@code = 1
|
|
|
|
|
2014-12-01 10:18:39 -04:00
|
|
|
exports.InvalidCredentials = class InvalidCredentials extends TypedError
|
|
|
|
constructor: ->
|
|
|
|
@message = 'Invalid credentials'
|
|
|
|
@code = 1
|
|
|
|
|
2014-11-26 10:32:57 -04:00
|
|
|
exports.NotAny = class NotAny extends TypedError
|
|
|
|
constructor: (name) ->
|
|
|
|
@message = "You don't have any #{name}"
|
|
|
|
@code = 0
|
2014-11-24 14:00:35 -04:00
|
|
|
|
|
|
|
exports.handle = (error, exit = true) ->
|
|
|
|
return if not error? or error not instanceof Error
|
|
|
|
|
|
|
|
if error.message?
|
|
|
|
log.error(error.message)
|
|
|
|
|
2014-11-26 10:32:57 -04:00
|
|
|
if _.isNumber(error.code)
|
|
|
|
errorCode = error.code
|
|
|
|
else
|
|
|
|
errorCode = 1
|
|
|
|
|
|
|
|
process.exit(errorCode) if exit
|