Skip to content

Commit

Permalink
chore: wrap update link stats in a try catch to prevent errors bubbling
Browse files Browse the repository at this point in the history
  • Loading branch information
gweiying committed Mar 21, 2024
1 parent 264fa6f commit 842cdc1
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/server/modules/redirect/services/RedirectService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { DependencyIds } from '../../../constants'
import { NotFoundError } from '../../../util/error'
import { RedirectResult, RedirectType } from '..'
import { LinkStatisticsService } from '../../analytics/interfaces'
import { ogUrl } from '../../../config'
import { logger, ogUrl } from '../../../config'
import { CookieArrayReducerService, CrawlerCheckService } from '.'

@injectable()
Expand Down Expand Up @@ -54,8 +54,12 @@ export class RedirectService {
const longUrl = await this.urlRepository.getLongUrl(shortUrl)

// Update clicks and click statistics in database.
this.linkStatisticsService.updateLinkStatistics(shortUrl, userAgent)

try {
this.linkStatisticsService.updateLinkStatistics(shortUrl, userAgent)
} catch (e) {
// updates wrapped in a try-catch block to prevent errors from bubbling up
logger.warn('error updating link statistics')
}
if (this.crawlerCheckService.isCrawler(userAgent)) {
return {
longUrl,
Expand Down

0 comments on commit 842cdc1

Please sign in to comment.