From 59983400708292cff5b3062d1e461e2036673f97 Mon Sep 17 00:00:00 2001 From: Nathan Friend Date: Thu, 17 Jun 2021 16:37:27 -0400 Subject: [PATCH] fix: better error logging for network errors --- lib/publish.js | 67 +++++++++++++++++++++++++++++++++----------------- 1 file changed, 45 insertions(+), 22 deletions(-) diff --git a/lib/publish.js b/lib/publish.js index 19e03293..d2384766 100644 --- a/lib/publish.js +++ b/lib/publish.js @@ -59,9 +59,20 @@ module.exports = async (pluginConfig, context) => { // Uploaded assets to the project const form = new FormData(); form.append('file', createReadStream(file)); - const {url, alt} = await got - .post(urlJoin(gitlabApiUrl, `/projects/${encodedRepoId}/uploads`), {...apiOptions, body: form}) - .json(); + + const uploadEndpoint = urlJoin(gitlabApiUrl, `/projects/${encodedRepoId}/uploads`); + + debug('POST-ing the file %s to %s', file, uploadEndpoint); + + let response; + try { + response = await got.post(uploadEndpoint, {...apiOptions, body: form}).json(); + } catch (error) { + logger.error('An error occurred while uploading %s to the GitLab project uploads API:\n%O', file, error); + throw error; + } + + const {url, alt} = response; assetsList.push({label, alt, url, type, filepath}); @@ -71,26 +82,38 @@ module.exports = async (pluginConfig, context) => { } debug('Create a release for git tag %o with commit %o', gitTag, gitHead); - await got.post(urlJoin(gitlabApiUrl, `/projects/${encodedRepoId}/releases`), { - ...apiOptions, - json: { - /* eslint-disable camelcase */ - tag_name: gitTag, - description: notes && notes.trim() ? notes : gitTag, - milestones, - assets: { - links: assetsList.map(({label, alt, url, type, filepath}) => { - return { - name: label || alt, - url: urlJoin(gitlabUrl, repoId, url), - link_type: type, - filepath, - }; - }), - }, - /* eslint-enable camelcase */ + + const createReleaseEndpoint = urlJoin(gitlabApiUrl, `/projects/${encodedRepoId}/releases`); + + const json = { + /* eslint-disable camelcase */ + tag_name: gitTag, + description: notes && notes.trim() ? notes : gitTag, + milestones, + assets: { + links: assetsList.map(({label, alt, url, type, filepath}) => { + return { + name: label || alt, + url: urlJoin(gitlabUrl, repoId, url), + link_type: type, + filepath, + }; + }), }, - }); + /* eslint-enable camelcase */ + }; + + debug('POST-ing the following JSON to %s:\n%s', createReleaseEndpoint, JSON.stringify(json, null, 2)); + + try { + await got.post(createReleaseEndpoint, { + ...apiOptions, + json, + }); + } catch (error) { + logger.error('An error occurred while making a request to the GitLab release API:\n%O', error); + throw error; + } logger.log('Published GitLab release: %s', gitTag);