Skip to content

Commit

Permalink
Update error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
alexs-mparticle committed Nov 20, 2024
1 parent e8be568 commit 5864e6f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
8 changes: 5 additions & 3 deletions src/identityApiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ export default function IdentityAPIClient(

if (mpInstance._Store.identityCallInFlight) {
invokeCallback(
callback as Callback,
callback,
HTTPCodes.activeIdentityRequest,
'There is currently an Identity request processing. Please wait for this to return before requesting again'
);
Expand Down Expand Up @@ -234,11 +234,13 @@ export default function IdentityAPIClient(
false
);
} catch (err) {
const errorMessage = (err as Error).message || 'Unknown Error';

mpInstance._Store.identityCallInFlight = false;
invokeCallback(
callback as Callback,
callback,
HTTPCodes.noHttpCoverage,
err.toString()
errorMessage,
);
error('Error sending identity request to servers' + ' - ' + err);
}
Expand Down
3 changes: 1 addition & 2 deletions src/sdkRuntimeModels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { DataPlanVersion } from '@mparticle/data-planning-models';
import {
MPConfiguration,
MPID,
Callback,
IdentityApiData,
} from '@mparticle/web-sdk';
import { IStore } from './store';
Expand Down Expand Up @@ -287,7 +286,7 @@ export interface SDKHelpersApi {
): boolean;
isObject?(item: any);
invokeCallback?(
callback: Callback,
callback: IdentityCallback,
code: number,
body: string,
mParticleUser?: IMParticleUser,
Expand Down
2 changes: 1 addition & 1 deletion test/src/tests-identityApiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ describe('Identity Api Client', () => {
it('should call invokeCallback with an error if the fetch fails', async () => {
fetchMock.post(urls.identify, {
status: 500,
throws: 'server error',
throws: { message: 'server error' },
}, {
overwriteRoutes: true,
});
Expand Down

0 comments on commit 5864e6f

Please sign in to comment.