Improve Request Error Handling

This commit is contained in:
Frank 2020-06-08 19:59:37 +02:00
parent 5d7e3ef283
commit d3ea5fce44
2 changed files with 22 additions and 2 deletions

10
dist/index.js vendored
View file

@ -2653,7 +2653,17 @@ const instance = axios.create(instanceConfig);
core.setOutput('response', JSON.stringify(response.data)) core.setOutput('response', JSON.stringify(response.data))
} catch (error) { } catch (error) {
if (error.toJSON) {
core.setOutput(error.toJSON());
}
if (error.response) {
core.setFailed(JSON.stringify({ code: error.response.code, message: error.response.data })) 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);
}
} }
})() })()

View file

@ -57,6 +57,16 @@ const instance = axios.create(instanceConfig);
core.setOutput('response', JSON.stringify(response.data)) core.setOutput('response', JSON.stringify(response.data))
} catch (error) { } catch (error) {
if (error.toJSON) {
core.setOutput(error.toJSON());
}
if (error.response) {
core.setFailed(JSON.stringify({ code: error.response.code, message: error.response.data })) 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);
}
} }
})() })()