Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: better error logging for network errors #245

Merged
merged 2 commits into from
Jun 22, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 45 additions & 22 deletions lib/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -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});

Expand All @@ -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);

Expand Down