diff --git a/src/errors.ts b/src/errors.ts index 878db152..b736a5cf 100644 --- a/src/errors.ts +++ b/src/errors.ts @@ -23,19 +23,19 @@ export class RadarLocationError extends RadarError { } } -export class RadarLocationPermissionsError extends RadarError { +export class RadarPermissionsError extends RadarError { constructor(message: string) { super(message); - this.name = 'RadarLocationPermissionsError'; + this.name = 'RadarPermissionsError'; this.status = 'ERROR_PERMISSIONS'; } } -export class RadarDesktopAppError extends RadarError { +export class RadarVerifyAppError extends RadarError { constructor() { - super('Desktop app not running.'); - this.name = 'RadarDesktopAppError'; - this.status = 'ERROR_DESKTOP_APP'; + super('Radar Verify app not running.'); + this.name = 'RadarVerifyAppError'; + this.status = 'ERROR_VERIFY_APP'; } } @@ -131,11 +131,11 @@ export class RadarServerError extends RadarError { } } -export class RadarTimeoutError extends RadarError { +export class RadarNetworkError extends RadarError { constructor() { super('Request timed out.'); - this.name = 'RadarTimeoutError'; - this.status = 'ERROR_TIMED_OUT'; + this.name = 'RadarNetworkError'; + this.status = 'ERROR_NETWORK'; } } diff --git a/src/http.ts b/src/http.ts index baecd027..fca5bcbe 100644 --- a/src/http.ts +++ b/src/http.ts @@ -4,18 +4,18 @@ import Logger from './logger'; import { RadarBadRequestError, - RadarDesktopAppError, RadarForbiddenError, RadarLocationError, - RadarLocationPermissionsError, + RadarNetworkError, RadarNotFoundError, RadarPaymentRequiredError, + RadarPermissionsError, RadarPublishableKeyError, RadarRateLimitError, RadarServerError, - RadarTimeoutError, RadarUnauthorizedError, RadarUnknownError, + RadarVerifyAppError, } from './errors'; export type HttpMethod = 'GET' | 'PUT' | 'PATCH' | 'POST' | 'DELETE'; @@ -110,11 +110,11 @@ class Http { const error = response?.meta?.error; if (error === 'ERROR_PERMISSIONS') { - return reject(new RadarLocationPermissionsError('Location permissions not granted.')); + return reject(new RadarPermissionsError('Location permissions not granted.')); } else if (error === 'ERROR_LOCATION') { return reject(new RadarLocationError('Could not determine location.')); } else if (error === 'ERROR_NETWORK') { - return reject(new RadarTimeoutError()); + return reject(new RadarNetworkError()); } if (xhr.status == 200) { diff --git a/src/navigator.ts b/src/navigator.ts index 519dc7f7..01fdfba4 100644 --- a/src/navigator.ts +++ b/src/navigator.ts @@ -1,7 +1,7 @@ import Config from './config'; import Logger from './logger'; import Storage from './storage'; -import { RadarLocationError, RadarLocationPermissionsError } from './errors'; +import { RadarLocationError, RadarPermissionsError } from './errors'; import type { LocationAuthorization, NavigatorPosition } from './types'; @@ -92,7 +92,7 @@ class Navigator { // https://developer.mozilla.org/en-US/docs/Web/API/GeolocationPositionError // code 1 means permission denied // codes 2 and 3 mean location unavailable or timeout - return reject(new RadarLocationPermissionsError('Permission denied.')); + return reject(new RadarPermissionsError('Permission denied.')); } return reject(new RadarLocationError('Could not determine location.')); }, diff --git a/test/api/track.test.ts b/test/api/track.test.ts index ab735a8a..b5d4a516 100644 --- a/test/api/track.test.ts +++ b/test/api/track.test.ts @@ -52,7 +52,7 @@ describe('Track', () => { await Track.trackOnce({}); throw new Error('Test did not throw expected error.'); } catch (err: any) { - expect(err.name).toEqual('RadarLocationPermissionsError'); + expect(err.name).toEqual('RadarPermissionsError'); expect(err.message).toEqual('Permission denied.'); expect(err.status).toEqual('ERROR_PERMISSIONS'); } diff --git a/test/navigator.test.ts b/test/navigator.test.ts index e7de7534..e00f7be9 100644 --- a/test/navigator.test.ts +++ b/test/navigator.test.ts @@ -7,12 +7,12 @@ import { nycOffice, enableLocation } from './utils'; describe('Navigator', () => { describe('getCurrentPosition', () => { describe('location permissions denied', () => { - it('should throw a RadarLocationPermissionsError', async () => { + it('should throw a RadarPermissionsError', async () => { try { await Navigator.getCurrentPosition(); throw new Error('Response should not succeed.'); } catch (err: any) { - expect(err.name).toEqual('RadarLocationPermissionsError'); + expect(err.name).toEqual('RadarPermissionsError'); expect(err.message).toEqual('Permission denied.'); expect(err.status).toEqual('ERROR_PERMISSIONS'); }