From d3ea5fce441fbc337b2ec1656d0756906da6ea8a Mon Sep 17 00:00:00 2001 From: Frank Date: Mon, 8 Jun 2020 19:59:37 +0200 Subject: [PATCH] Improve Request Error Handling --- dist/index.js | 12 +++++++++++- src/index.js | 12 +++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/dist/index.js b/dist/index.js index 2a05b01..df51b0e 100644 --- a/dist/index.js +++ b/dist/index.js @@ -2653,7 +2653,17 @@ const instance = axios.create(instanceConfig); core.setOutput('response', JSON.stringify(response.data)) } catch (error) { - core.setFailed(JSON.stringify({ code: error.response.code, message: error.response.data })) + if (error.toJSON) { + core.setOutput(error.toJSON()); + } + + if (error.response) { + core.setFailed(JSON.stringify({ code: error.response.code, message: error.response.data })) + } else if (error.request) { + core.setFailed(JSON.stringify({ error: "no response received" })); + } else { + core.setFailed(error.message); + } } })() diff --git a/src/index.js b/src/index.js index 2200c9c..38c535d 100644 --- a/src/index.js +++ b/src/index.js @@ -57,6 +57,16 @@ const instance = axios.create(instanceConfig); core.setOutput('response', JSON.stringify(response.data)) } catch (error) { - core.setFailed(JSON.stringify({ code: error.response.code, message: error.response.data })) + if (error.toJSON) { + core.setOutput(error.toJSON()); + } + + if (error.response) { + core.setFailed(JSON.stringify({ code: error.response.code, message: error.response.data })) + } else if (error.request) { + core.setFailed(JSON.stringify({ error: "no response received" })); + } else { + core.setFailed(error.message); + } } })()