Avoid trying to send a response to API calls after we've already sent an error

In some cases we were using early `return res.status(...).send(...)` to send 400 errors
but this happened inside a promise chain that later sent another status and response.

We fix this with the correct indentation of the success response so that an early return doesn't fall there.

Change-Type: patch
Signed-off-by: Pablo Carranza Velez <pablo@resin.io>
This commit is contained in:
Pablo Carranza Velez 2018-03-09 14:48:34 -08:00
parent 79b4d39acd
commit f76aacc7fb

View File

@ -136,10 +136,10 @@ createApplicationManagerRouter = (applications) ->
.then (app) ->
service = app?.services?[0]
if !service?
return res.status(400).send('App not found after running action')
throw new Error('App not found after running action')
return service
.then (service) ->
res.status(200).json({ containerId: service.containerId })
.then (service) ->
res.status(200).json({ containerId: service.containerId })
.catch (err) ->
res.status(503).send(err?.message or err or 'Unknown error')
@ -213,8 +213,8 @@ createApplicationManagerRouter = (applications) ->
return res.status(404).send(errMsg)
applications.setTargetVolatileForService(service.imageId, running: action != 'stop')
applications.executeStepAction(serviceAction(action, service.serviceId, service, service, { wait: true }), { skipLock: true })
.then ->
res.status(200).send('OK')
.then ->
res.status(200).send('OK')
.catch (err) ->
res.status(503).send(err?.message or err or 'Unknown error')