diff --git a/src/players/services/steam-api.service.spec.ts b/src/players/services/steam-api.service.spec.ts index 772c2abbd..fa86f86fa 100644 --- a/src/players/services/steam-api.service.spec.ts +++ b/src/players/services/steam-api.service.spec.ts @@ -1,6 +1,6 @@ import { Test, TestingModule } from '@nestjs/testing'; import { SteamApiService } from './steam-api.service'; -import { of } from 'rxjs'; +import { of, throwError } from 'rxjs'; import { readFileSync } from 'fs'; import { resolve } from 'path'; import { HttpService } from '@nestjs/common'; @@ -58,7 +58,7 @@ describe('SteamApiService', () => { describe('with response code 500', () => { beforeEach(() => { - jest.spyOn(httpService, 'get').mockReturnValue(of({ status: 500 } as any)); + jest.spyOn(httpService, 'get').mockReturnValue(throwError({ status: 500 } as any)); }); it('should throw an error', async () => { diff --git a/src/players/services/steam-api.service.ts b/src/players/services/steam-api.service.ts index 5e2b322d7..fe16efe01 100644 --- a/src/players/services/steam-api.service.ts +++ b/src/players/services/steam-api.service.ts @@ -1,6 +1,6 @@ import { Injectable, HttpService } from '@nestjs/common'; import { Environment } from '@/environment/environment'; -import { map, switchMap } from 'rxjs/operators'; +import { map, switchMap, catchError } from 'rxjs/operators'; import { floor } from 'lodash'; import { of, throwError } from 'rxjs'; @@ -29,17 +29,14 @@ export class SteamApiService { async getTf2InGameHours(steamId64: string): Promise { return this.httpService.get(`${this.userStatsForGameEndpoint}/?appid=${this.tf2AppId}&key=${this.environment.steamApiKey}&steamid=${steamId64}&format=json`).pipe( switchMap(response => { - if (response.status === 200) { - return of( - response.data.playerstats.stats - .filter(s => /\.accum\.iPlayTime$/.test(s.name)) - .reduce((sum, curr) => sum + curr.value, 0) - ); - } else { - return throwError(new Error('cannot verify in-game hours for TF2')); - } + return of( + response.data.playerstats.stats + .filter(s => /\.accum\.iPlayTime$/.test(s.name)) + .reduce((sum, curr) => sum + curr.value, 0) + ); }), map(seconds => floor(seconds / 60 / 60)), + catchError(() => throwError(new Error('cannot verify in-game hours for TF2'))), ).toPromise(); }