From 70f7c718ed6eee3433ea87bcca83ce6551e8af78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Thorsnes?= Date: Fri, 22 Sep 2023 08:45:46 +0200 Subject: [PATCH] added sliglty better error handling again --- lib/e18.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/e18.js b/lib/e18.js index 26f6977..6788fa0 100644 --- a/lib/e18.js +++ b/lib/e18.js @@ -21,8 +21,10 @@ module.exports.createJob = async blobName => { const { data } = await axios.post(`${E18_URL}/jobs`, payload, headers) return data._id } catch (error) { - const { status, message } = error.response - logger('error', ['e18', 'createJob', message, status]) + const errorMsg = error.response?.data || error.stack || error.toString() + const status = error.response?.status || 500 + const message = error.response?.message || error.toString() + logger('error', ['e18', 'createJob', message, status, errorMsg]) throw error } } @@ -38,8 +40,10 @@ module.exports.createTask = async (jobId, payload) => { const { data } = await axios.post(`${E18_URL}/jobs/${jobId}/tasks`, payload, headers) return data._id } catch (error) { - const { status, message } = error.response - logger('error', ['e18', 'createTask', message, status]) + const errorMsg = error.response?.data || error.stack || error.toString() + const status = error.response?.status || 500 + const message = error.response?.message || error.toString() + logger('error', ['e18', 'createTask', message, status, errorMsg]) throw error } } @@ -56,8 +60,10 @@ module.exports.complete = async blobContent => { blobContent.flow.e18Job = { status: 'finished' } return blobContent } catch (error) { - const { status, message } = error.response - logger('error', ['e18', 'complete', message, status]) + const errorMsg = error.response?.data || error.stack || error.toString() + const status = error.response?.status || 500 + const message = error.response?.message || error.toString() + logger('error', ['e18', 'complete', message, status, errorMsg]) blobContent.flow.e18Job = { status: 'failed' } return blobContent }