Skip to content

Commit

Permalink
De-dup the error handling branches.
Browse files Browse the repository at this point in the history
  • Loading branch information
dominiccooney committed Nov 18, 2024
1 parent 13817d2 commit 7ebfde2
Showing 1 changed file with 3 additions and 12 deletions.
15 changes: 3 additions & 12 deletions lib/shared/src/sourcegraph-api/graphql/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,20 +208,13 @@ export class GraphQLResultCache<V> {
this.fetchTimeMsec = now

let thisFetch: Promise<V | Error> | undefined = undefined
const handleError = (error: any): void => {
if (this.lastFetch === thisFetch && error instanceof Error) {
this.lastResult = error
this.retryCount++
this.aborts = undefined
}
}
try {
thisFetch = fetcher(this.aborts.signal)
this.lastResult = undefined
this.lastFetch = thisFetch = fetcher(this.aborts.signal)
} catch (error) {
// We did not succeed in even creating a Promise, so synthesize one.
this.lastFetch = thisFetch = Promise.reject(error)
handleError(error)
return thisFetch
this.lastResult = error instanceof Error ? error : new Error('unknown error')
}
void (async () => {
try {
Expand All @@ -245,8 +238,6 @@ export class GraphQLResultCache<V> {
// update the cache's state.
}
})()
this.lastResult = undefined
this.lastFetch = thisFetch
return thisFetch
}
}

0 comments on commit 7ebfde2

Please sign in to comment.