Improve clarity of curl error handling

This commit is contained in:
Brycey92 2024-03-05 13:01:27 -05:00
parent 3b7b9ea2bb
commit 7d943f4f8b
2 changed files with 13 additions and 4 deletions

View file

@ -66,7 +66,10 @@ fetch_orga_repos() {
log "Fetch organization repos."
if ! $CURL -X GET $GITEA_URL/api/v1/orgs/${gitea_organization}/repos "${header_options[@]}" >${jsonoutput}/1.json 2>${jsonoutput}/stderr.txt; then
local code=$(<${jsonoutput}/result.txt)
if (( code != 404 ));then # 404 == orga not found
if (( code == 404 ));then # 404 == orga not found
log "404: Gitea orga not found. Nothing to do. Exiting."
exit 1
else
cat ${jsonoutput}/stderr.txt >&2
fi
fi
@ -95,7 +98,9 @@ delete_orga() {
log "Delete orga."
if ! $CURL -X DELETE $GITEA_URL/api/v1/orgs/${gitea_organization} "${header_options[@]}" > ${jsonoutput}/result.txt 2>${jsonoutput}/stderr.txt; then
local code=$(<${jsonoutput}/result.txt)
if (( code != 404 ));then # 404 == orga not found
if (( code == 404 ));then # 404 == orga not found
log "404: Gitea orga not found. Is it already deleted?"
else
cat ${jsonoutput}/stderr.txt >&2
fi
fi

View file

@ -163,7 +163,9 @@ create_migration_repo() {
log "Create migration repo."
if ! $CURL -w "%{http_code}\n" "${header_options[@]}" -d @- -X POST $GITEA_URL/api/v1/repos/migrate > ${jsonoutput}/result.txt 2>${jsonoutput}/stderr.txt; then
local code=$(<${jsonoutput}/result.txt)
if (( code != 409 ));then # 409 == repo already exits
if (( code == 409 ));then # 409 == repo already exits
log "409: Gitea repo already exists. Skipping migration."
else
cat ${jsonoutput}/stderr.txt >&2
fi
fi
@ -175,7 +177,9 @@ create_migration_orga() {
log "Create migration orga with name: ${gitea_organization}"
if ! $CURL -X POST $GITEA_URL/api/v1/orgs "${header_options[@]}" --data '{"username": "'"${gitea_organization}"'", "visibility": "'"${visibility}"'"}' > ${jsonoutput}/result.txt 2>${jsonoutput}/stderr.txt; then
local code=$(<${jsonoutput}/result.txt)
if (( code != 422 ));then # 422 == orga already exits
if (( code == 422 ));then # 422 == orga already exits
log "422: Gitea orga already exists. Skipping creation."
else
cat ${jsonoutput}/stderr.txt >&2
fi
fi