mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2025-02-20 09:46:19 +00:00
Use typed-error for the disconnected error.
This commit is contained in:
parent
e054b36d58
commit
0b93c1ce2c
@ -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"
|
||||
|
@ -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!
|
||||
|
Loading…
x
Reference in New Issue
Block a user