Prefer err.message when reporting errors from dockerode, then err.json and err.reason

Errors from docker-modem that are passed from dockerode can have a "json" or "reason" property,
but that is generally less descriptive than the more standard "message", and can show up in the logs
as `[object Object]`. This commit changes it so that we log err.message if it is non-empty, and otherwise
look for json and reason.

Change-Type: patch
Signed-off-by: Pablo Carranza Velez <pablo@resin.io>
This commit is contained in:
Pablo Carranza Velez 2017-08-24 10:20:22 -07:00
parent a8e11b51a0
commit dbb4fd8292

View File

@ -130,11 +130,11 @@ logSystemEvent = (logType, app = {}, error) ->
message = "#{logType.humanName} '#{app.imageId}'"
if error?
# Report the message from the original cause to the user.
errMessage = error.json
errMessage = error.message
if _.isEmpty(errMessage)
errMessage = error.json
if _.isEmpty(errMessage)
errMessage = error.reason
if _.isEmpty(errMessage)
errMessage = error.message
if _.isEmpty(errMessage)
errMessage = 'Unknown cause'
message += " due to '#{errMessage}'"