Skip to content

Commit f131e33

Browse files
committed
fix: reupload again if failed with "502 Bad Gateway" (3 times)
1 parent d1801ae commit f131e33

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
"babel-plugin-array-includes": "^2.0.3",
7676
"babel-plugin-transform-es2015-parameters": "^6.7.0",
7777
"electron-download": "^2.0.0",
78-
"eslint": "^2.3.0",
78+
"eslint": "^2.4.0",
7979
"eslint-plugin-ava": "sindresorhus/eslint-plugin-ava",
8080
"ghooks": "^1.0.3",
8181
"json-parse-helpfulerror": "^1.0.3",

src/gitHubPublisher.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export class GitHubPublisher implements Publisher {
4242

4343
private async init(): Promise<Release> {
4444
// we don't use "Get a release by tag name" because "tag name" means existing git tag, but we draft release and don't create git tag
45-
let releases = await gitHubRequest<Array<Release>>(`/repos/${this.owner}/${this.repo}/releases`, this.token)
45+
const releases = await gitHubRequest<Array<Release>>(`/repos/${this.owner}/${this.repo}/releases`, this.token)
4646
for (let release of releases) {
4747
if (release.tag_name === this.tag) {
4848
if (!release.draft) {
@@ -75,6 +75,7 @@ export class GitHubPublisher implements Publisher {
7575

7676
const parsedUrl = parseUrl(release.upload_url.substring(0, release.upload_url.indexOf("{")) + "?name=" + fileName)
7777
const fileStat = await stat(path)
78+
let badGatewayCount = 0
7879
uploadAttempt: for (let i = 0; i < 3; i++) {
7980
const progressBar = (<ReadStream>process.stdin).isTTY ? new ProgressBar(`Uploading ${fileName} [:bar] :percent :etas`, {
8081
total: fileStat.size,
@@ -107,8 +108,7 @@ export class GitHubPublisher implements Publisher {
107108
}
108109
catch (e) {
109110
if (e instanceof HttpError) {
110-
const httpError = <HttpError>e
111-
if (httpError.response.statusCode === 422 && httpError.description != null && httpError.description.errors != null && httpError.description.errors[0].code === "already_exists") {
111+
if (e.response.statusCode === 422 && e.description != null && e.description.errors != null && e.description.errors[0].code === "already_exists") {
112112
// delete old artifact and re-upload
113113
log("Artifact %s already exists, overwrite one", fileName)
114114
const assets = await gitHubRequest<Array<Asset>>(`/repos/${this.owner}/${this.repo}/releases/${release.id}/assets`, this.token)
@@ -122,6 +122,9 @@ export class GitHubPublisher implements Publisher {
122122
log("Artifact %s not found, trying to upload again", fileName)
123123
continue
124124
}
125+
else if (e.response.statusCode === 502 && badGatewayCount++ < 3) {
126+
continue
127+
}
125128
}
126129

127130
throw e

test/src/ArtifactPublisherTest.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import test from "ava-tf"
1+
import test from "./helpers/avaEx"
22
import { GitHubPublisher } from "out/gitHubPublisher"
33
import { HttpError } from "out/gitHubRequest"
44
import { join } from "path"

0 commit comments

Comments
 (0)