Use typed-error for the disconnected error.

This commit is contained in:
Pagan Gazzard 2014-12-19 14:24:52 +00:00 committed by Pablo Carranza Vélez
parent e054b36d58
commit 0b93c1ce2c
2 changed files with 8 additions and 5 deletions

View File

@ -23,7 +23,8 @@
"request": "~2.22.0",
"resin-platform-api": "git+ssh://git@bitbucket.org:rulemotion/resin-platform-api.git#v0.2.7",
"sqlite3": "~2.1.19",
"tty.js": "~0.2.13"
"tty.js": "~0.2.13",
"typed-error": "~0.1.0"
},
"engines": {
"node": "0.10.22"

View File

@ -2,6 +2,9 @@ Promise = require 'bluebird'
ngrok = Promise.promisifyAll require 'ngrok'
tty = Promise.promisifyAll require 'tty.js'
knex = require './db'
TypedError = require 'typed-error'
class DisconnectedError extends TypedError
# socat UNIX:/data/host -,raw,echo=0
@ -24,13 +27,12 @@ exports.start = (appId) ->
.then ->
ngrok.connectAsync(port)
DISCONNECTED = 'Disconnected'
disconnectedErr = (err) -> return err.message is DISCONNECTED
exports.stop = (appId) ->
if !apps[appId]?
return Promise.resolve()
apps[appId] = apps[appId].then (url) ->
ngrok.disconnectAsync(url)
.then ->
throw new Error(DISCONNECTED)
return apps[appId].catch disconnectedErr, -> # All good!
# We throw an error so that `.start` will catch and restart the session.
throw new DisconnectedError()
return apps[appId].catch DisconnectedError, -> # All good, since we want to disconnect here!