Skip to content

Commit 30346cc

Browse files
authored
Merge pull request #40 from highcharts/bugfix/failed-download
Bugfix/failed download
2 parents 0a2d610 + ccbc0a7 commit 30346cc

File tree

7 files changed

+446
-190
lines changed

7 files changed

+446
-190
lines changed

app/download.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ async function downloadSourceFolder (outputDir, repositoryURL, branch) {
8989
* @param {string} branch
9090
* @returns Promise<[{}]>
9191
*/
92-
async function downloadSourceFolderGit (outputDir, branch) {
92+
async function downloadSourceFolderGit (outputDir, branch, mode = 'tar') {
9393
log(0, `Downloading source for commit ${branch} using git`)
9494

9595
const responses = []
@@ -107,7 +107,7 @@ async function downloadSourceFolderGit (outputDir, branch) {
107107
cache: false,
108108
force: true,
109109
verbose: false,
110-
mode: 'tar'
110+
mode
111111
})
112112
emitter.clone(outputPath).then(() => {
113113
result.success = true

app/handlers.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,15 @@ async function serveBuildFile (branch, requestURL, useGitDownloader = true) {
325325
if (!isAlreadyDownloaded) {
326326
try {
327327
const downloadPromise = server.getDownloadJob(branch) || server.addDownloadJob(branch, useGitDownloader
328-
? downloadSourceFolderGit(pathCacheDirectory, branch)
328+
? downloadSourceFolderGit(pathCacheDirectory, branch).then(
329+
result => {
330+
// Sometimes the default degit/tiged tar mode fails to find a branch
331+
if (!result.some(res => res.success)) {
332+
log(2, 'Retrying using git mode')
333+
return downloadSourceFolderGit(pathCacheDirectory, branch, 'git')
334+
}
335+
}
336+
)
329337
: downloadSourceFolder(pathCacheDirectory, URL_DOWNLOAD, branch))
330338
if (!downloadPromise) throw new Error()
331339
} catch (error) {

app/middleware.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ function bodyJSONParser (req, res, next) {
4141
* @param {Function} next Call the next middleware function in the stack.
4242
*/
4343
function clientErrorHandler (err, req, res, next) {
44+
if (res?.writable) {
45+
next(err)
46+
}
47+
4448
res.status(response.error.status).send(response.error.body)
4549
next(err)
4650
}

0 commit comments

Comments
 (0)