Skip to content

Commit

Permalink
rename errors to match mobile SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
nickpatrick committed May 6, 2024
1 parent 88a48de commit 518d9f9
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 19 deletions.
18 changes: 9 additions & 9 deletions src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
}

Expand Down Expand Up @@ -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';
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions src/navigator.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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.'));
},
Expand Down
2 changes: 1 addition & 1 deletion test/api/track.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand Down
4 changes: 2 additions & 2 deletions test/navigator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand Down

0 comments on commit 518d9f9

Please sign in to comment.