Skip to content

Commit

Permalink
fix config polling logic
Browse files Browse the repository at this point in the history
  • Loading branch information
ajwootto committed Aug 6, 2024
1 parent fed5e79 commit 6f853c1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
6 changes: 3 additions & 3 deletions lib/shared/config-manager/src/CDNConfigSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ export class CDNConfigSource extends ConfigSource {
resStatus: res.status ?? undefined,
}

const projectConfig = (await res.json()) as unknown

this.logger.debug(
`Downloaded config, status: ${
res?.status
Expand All @@ -59,7 +57,9 @@ export class CDNConfigSource extends ConfigSource {
`Config not modified, using cache, etag: ${this.configEtag}` +
`, last-modified: ${this.configLastModified}`,
)
} else if (res.status === 200 && projectConfig) {
} else if (res.status === 200) {
const projectConfig = (await res.json()) as unknown

const lastModifiedHeader = res.headers.get('last-modified')
if (this.isLastModifiedHeaderOld(lastModifiedHeader ?? null)) {
this.logger.debug(
Expand Down
16 changes: 6 additions & 10 deletions lib/shared/config-manager/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,6 @@ export class EnvironmentConfigManager {
)
let projectConfig: ConfigBody | null = null
let retrievalMetadata: Record<string, unknown>
let userError: UserError | null = null
const startTime = Date.now()
let responseTimeMS = 0

Expand Down Expand Up @@ -269,7 +268,11 @@ export class EnvironmentConfigManager {
}
logError(ex)
if (ex instanceof UserError) {
userError = ex
throw ex
} else if (this._hasConfig) {
this.logger.warn(
`Failed to download config, using cached version. url: ${url}.`,
)
}
}

Expand All @@ -288,14 +291,7 @@ export class EnvironmentConfigManager {
}
}

if (this._hasConfig) {
this.logger.warn(
`Failed to download config, using cached version. url: ${url}.`,
)
} else if (userError) {
this.cleanup()
throw userError
} else {
if (!this._hasConfig) {
throw new Error('Failed to download DevCycle config.')
}
}
Expand Down

0 comments on commit 6f853c1

Please sign in to comment.