Skip to content

Commit

Permalink
feat(electron-updater): include full GitHub request url in the error …
Browse files Browse the repository at this point in the history
…message
  • Loading branch information
develar committed Feb 12, 2017
1 parent 3465306 commit a7d2992
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 28 deletions.
3 changes: 2 additions & 1 deletion .yarnclean
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,5 @@ Gruntfile.js
*.gz
*.md

!tslint/lib/test
!tslint/lib/test
!tslint\lib\test
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ environment:

install:
- ps: Install-Product node 6 x64
- node ./test/vendor/yarn.js
- node ./test/vendor/yarn.js --pure-lockfile

build: off

Expand Down
38 changes: 20 additions & 18 deletions packages/electron-updater/src/GitHubProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,41 +24,43 @@ export class GitHubProvider extends Provider<VersionInfo> {

async getLatestVersion(): Promise<UpdateInfo> {
const basePath = this.getBasePath()
let version

const cancellationToken = new CancellationToken()
try {
// do not use API to avoid limit
const releaseInfo = (await request<GithubReleaseInfo>(Object.assign({
path: `${basePath}/latest`,
headers: Object.assign({Accept: "application/json"}, this.requestHeaders)
}, this.baseUrl), cancellationToken))
version = (releaseInfo.tag_name.startsWith("v")) ? releaseInfo.tag_name.substring(1) : releaseInfo.tag_name
}
catch (e) {
throw new Error(`Unable to find latest version on github, please ensure a production release exists: ${e.stack || e.message}`)
}

const version = await this.getLatestVersionString(basePath, cancellationToken)
let result: any
const channelFile = getChannelFilename(getDefaultChannelName())
const channelFileUrlPath = `${basePath}/download/v${version}/${channelFile}`
const requestOptions = Object.assign({path: `${basePath}/download/v${version}/${channelFile}`, headers: this.requestHeaders || undefined}, this.baseUrl)
try {
result = await request<UpdateInfo>(Object.assign({path: channelFileUrlPath, headers: this.requestHeaders || undefined}, this.baseUrl), cancellationToken)
result = await request<UpdateInfo>(requestOptions, cancellationToken)
}
catch (e) {
if (e instanceof HttpError && e.response.statusCode === 404) {
throw new Error(`Cannot find ${channelFile} in the latest release artifacts: ${e.stack || e.message}`)
throw new Error(`Cannot find ${channelFile} in the latest release artifacts (${url.format(<any>requestOptions)}): ${e.stack || e.message}`)
}
throw e
}

validateUpdateInfo(result)
if (getCurrentPlatform() === "darwin") {
result.releaseJsonUrl = `${githubUrl(this.options)}/${channelFileUrlPath}`
result.releaseJsonUrl = `${githubUrl(this.options)}/${requestOptions.path}`
}
return result
}

private async getLatestVersionString(basePath: string, cancellationToken: CancellationToken): Promise<string> {
const requestOptions: RequestOptions = Object.assign({
path: `${basePath}/latest`,
headers: Object.assign({Accept: "application/json"}, this.requestHeaders)
}, this.baseUrl)
try {
// do not use API to avoid limit
const releaseInfo = (await request<GithubReleaseInfo>(requestOptions, cancellationToken))
return (releaseInfo.tag_name.startsWith("v")) ? releaseInfo.tag_name.substring(1) : releaseInfo.tag_name
}
catch (e) {
throw new Error(`Unable to find latest version on GitHub (${url.format(<any>requestOptions)}), please ensure a production release exists: ${e.stack || e.message}`)
}
}

private getBasePath() {
return `/${this.options.owner}/${this.options.repo}/releases`
}
Expand Down
20 changes: 12 additions & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1782,12 +1782,12 @@ js-yaml@^3.4.2, js-yaml@^3.7.0, js-yaml@^3.8.1:
esprima "^3.1.1"

jsbn@~0.1.0:
version "0.1.0"
resolved "https://registry.yarnpkg.com/jsbn/-/jsbn-0.1.0.tgz#650987da0dd74f4ebf5a11377a2aa2d273e97dfd"
version "0.1.1"
resolved "https://registry.yarnpkg.com/jsbn/-/jsbn-0.1.1.tgz#a5e654c2e5a2deb5f201d96cefbca80c0ef2f513"

jsdom@^9.9.1:
version "9.10.0"
resolved "https://registry.yarnpkg.com/jsdom/-/jsdom-9.10.0.tgz#72d04d9fd5f1164d016dc350ef889af6d0d1a25a"
version "9.11.0"
resolved "https://registry.yarnpkg.com/jsdom/-/jsdom-9.11.0.tgz#a95b0304e521a2ca5a63c6ea47bf7708a7a84591"
dependencies:
abab "^1.0.3"
acorn "^4.0.4"
Expand All @@ -1804,7 +1804,7 @@ jsdom@^9.9.1:
sax "^1.2.1"
symbol-tree "^3.2.1"
tough-cookie "^2.3.2"
webidl-conversions "^3.0.1"
webidl-conversions "^4.0.0"
whatwg-encoding "^1.0.1"
whatwg-url "^4.3.0"
xml-name-validator "^2.0.1"
Expand Down Expand Up @@ -2879,8 +2879,8 @@ supports-color@^3.1.2:
has-flag "^1.0.0"

symbol-tree@^3.2.1:
version "3.2.1"
resolved "https://registry.yarnpkg.com/symbol-tree/-/symbol-tree-3.2.1.tgz#8549dd1d01fa9f893c18cc9ab0b106b4d9b168cb"
version "3.2.2"
resolved "https://registry.yarnpkg.com/symbol-tree/-/symbol-tree-3.2.2.tgz#ae27db38f660a7ae2e1c3b7d1bc290819b8519e6"

sync-exec@^0.6.2:
version "0.6.2"
Expand Down Expand Up @@ -3110,10 +3110,14 @@ watch@~0.10.0:
version "0.10.0"
resolved "https://registry.yarnpkg.com/watch/-/watch-0.10.0.tgz#77798b2da0f9910d595f1ace5b0c2258521f21dc"

webidl-conversions@^3.0.0, webidl-conversions@^3.0.1:
webidl-conversions@^3.0.0:
version "3.0.1"
resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-3.0.1.tgz#24534275e2a7bc6be7bc86611cc16ae0a5654871"

webidl-conversions@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-4.0.0.tgz#0a8c727ae4e5649687b7742368dcfbf13ed40118"

whatwg-encoding@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/whatwg-encoding/-/whatwg-encoding-1.0.1.tgz#3c6c451a198ee7aec55b1ec61d0920c67801a5f4"
Expand Down

0 comments on commit a7d2992

Please sign in to comment.