Try catch the method calling fetch

Signed-off-by: cmoulliard <cmoulliard@redhat.com>
This commit is contained in:
cmoulliard
2023-12-20 11:49:55 +01:00
parent 1c91c52a09
commit 331c4c242a
@@ -57,10 +57,12 @@ const createGiteaProject = async (
// TODO
// Create a repository in Gitea
// API request: https://gitea.com/api/swagger#/user/createCurrentUserRepo
const response: Response = await fetch(
`${config.baseUrl}/api/v1/user/repos`,
fetchOptions,
);
let response: Response;
try {
response = await fetch(`${config.baseUrl}/api/v1/user/repos`, fetchOptions);
} catch (e) {
throw new Error(`Unable to create repository, ${e}`);
}
if (response.status !== 201) {
throw new Error(
`Unable to create repository, ${response.status} ${
@@ -168,8 +170,12 @@ export function createPublishGiteaAction(options: {
repoUrl,
description,
defaultBranch = 'main',
gitAuthorName = config.getOptionalString('scaffolder.defaultAuthor.name'),
gitAuthorEmail = config.getOptionalString('scaffolder.defaultAuthor.email'),
gitAuthorName = config.getOptionalString(
'scaffolder.defaultAuthor.name',
),
gitAuthorEmail = config.getOptionalString(
'scaffolder.defaultAuthor.email',
),
gitCommitMessage = 'initial commit',
sourcePath,
} = ctx.input;