Skip to content

Commit 25a9011

Browse files
author
Nathan Friend
authored
fix: better error logging for network errors (#245)
1 parent e8b15e2 commit 25a9011

File tree

1 file changed

+45
-22
lines changed

1 file changed

+45
-22
lines changed

lib/publish.js

Lines changed: 45 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,20 @@ module.exports = async (pluginConfig, context) => {
5959
// Uploaded assets to the project
6060
const form = new FormData();
6161
form.append('file', createReadStream(file));
62-
const {url, alt} = await got
63-
.post(urlJoin(gitlabApiUrl, `/projects/${encodedRepoId}/uploads`), {...apiOptions, body: form})
64-
.json();
62+
63+
const uploadEndpoint = urlJoin(gitlabApiUrl, `/projects/${encodedRepoId}/uploads`);
64+
65+
debug('POST-ing the file %s to %s', file, uploadEndpoint);
66+
67+
let response;
68+
try {
69+
response = await got.post(uploadEndpoint, {...apiOptions, body: form}).json();
70+
} catch (error) {
71+
logger.error('An error occurred while uploading %s to the GitLab project uploads API:\n%O', file, error);
72+
throw error;
73+
}
74+
75+
const {url, alt} = response;
6576

6677
assetsList.push({label, alt, url, type, filepath});
6778

@@ -71,26 +82,38 @@ module.exports = async (pluginConfig, context) => {
7182
}
7283

7384
debug('Create a release for git tag %o with commit %o', gitTag, gitHead);
74-
await got.post(urlJoin(gitlabApiUrl, `/projects/${encodedRepoId}/releases`), {
75-
...apiOptions,
76-
json: {
77-
/* eslint-disable camelcase */
78-
tag_name: gitTag,
79-
description: notes && notes.trim() ? notes : gitTag,
80-
milestones,
81-
assets: {
82-
links: assetsList.map(({label, alt, url, type, filepath}) => {
83-
return {
84-
name: label || alt,
85-
url: urlJoin(gitlabUrl, repoId, url),
86-
link_type: type,
87-
filepath,
88-
};
89-
}),
90-
},
91-
/* eslint-enable camelcase */
85+
86+
const createReleaseEndpoint = urlJoin(gitlabApiUrl, `/projects/${encodedRepoId}/releases`);
87+
88+
const json = {
89+
/* eslint-disable camelcase */
90+
tag_name: gitTag,
91+
description: notes && notes.trim() ? notes : gitTag,
92+
milestones,
93+
assets: {
94+
links: assetsList.map(({label, alt, url, type, filepath}) => {
95+
return {
96+
name: label || alt,
97+
url: urlJoin(gitlabUrl, repoId, url),
98+
link_type: type,
99+
filepath,
100+
};
101+
}),
92102
},
93-
});
103+
/* eslint-enable camelcase */
104+
};
105+
106+
debug('POST-ing the following JSON to %s:\n%s', createReleaseEndpoint, JSON.stringify(json, null, 2));
107+
108+
try {
109+
await got.post(createReleaseEndpoint, {
110+
...apiOptions,
111+
json,
112+
});
113+
} catch (error) {
114+
logger.error('An error occurred while making a request to the GitLab release API:\n%O', error);
115+
throw error;
116+
}
94117

95118
logger.log('Published GitLab release: %s', gitTag);
96119

0 commit comments

Comments
 (0)