Skip to content

Commit b505263

Browse files
Address PR Comments
1 parent 8170c03 commit b505263

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

src/identityApiClient.ts

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,10 @@ export default function IdentityAPIClient(
122122
case HTTP_ACCEPTED:
123123
case HTTP_OK:
124124

125-
// 400 error will has a body and will go through the happy path to report the error
125+
// Our Identity API will return a 400 error if there is an issue with the requeest body
126+
// such as if the body is empty or one of the attirbutes is missing or malformed
127+
// A 400 will return an error in the response body and will go through the happy path to report the error
128+
// Any unhandled errors, such as 500 or 429, will be caught here as well
126129
case HTTP_BAD_REQUEST:
127130

128131
// FetchUploader returns the response as a JSON object that we have to await
@@ -145,11 +148,10 @@ export default function IdentityAPIClient(
145148
? JSON.parse(xhrResponse.responseText)
146149
: '';
147150

148-
// https://go.mparticle.com/work/SQDSDKS-6670
149-
message =
150-
'Successfully sent forwarding stats to mParticle Servers';
151151
}
152152

153+
// https://go.mparticle.com/work/SQDSDKS-6670
154+
message = 'Successfully sent alias request to mParticle Servers';
153155

154156
if (response.status === HTTP_BAD_REQUEST) {
155157
// 400 has an error message, but 403 doesn't
@@ -168,7 +170,11 @@ export default function IdentityAPIClient(
168170

169171
break;
170172

171-
// 401 and 403 have no bodies and should be rejected outright
173+
// Our Identity API will return:
174+
// - 401 if the `x-mp-key` is incorrect or missing
175+
// - 403 if the there is a permission or account issue related to the `x-mp-key`
176+
// 401 and 403 have no response bodies and should be rejected outright
177+
// Any unhandled errors, such as 500 or 429, will be caught here as well
172178
default: {
173179
throw new Error('Received HTTP Code of ' + response.status);
174180
}
@@ -245,7 +251,9 @@ export default function IdentityAPIClient(
245251
case HTTP_ACCEPTED:
246252
case HTTP_OK:
247253

248-
// 400 error will has a body and will go through the happy path to report the error
254+
// Our Identity API will return a 400 error if there is an issue with the requeest body
255+
// such as if the body is empty or one of the attirbutes is missing or malformed
256+
// A 400 will return an error in the response body and will go through the happy path to report the error
249257
case HTTP_BAD_REQUEST:
250258

251259
// FetchUploader returns the response as a JSON object that we have to await
@@ -280,7 +288,10 @@ export default function IdentityAPIClient(
280288

281289
break;
282290

283-
// 401 and 403 have no bodies and should be rejected outright
291+
// Our Identity API will return:
292+
// - 401 if the `x-mp-key` is incorrect or missing
293+
// - 403 if the there is a permission or account issue related to the `x-mp-key`
294+
// 401 and 403 have no response bodies and should be rejected outright
284295
default: {
285296
throw new Error('Received HTTP Code of ' + response.status);
286297
}

test/src/tests-identityApiClient.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -387,10 +387,7 @@ describe('Identity Api Client', () => {
387387

388388
const mpInstance: MParticleWebSDK = ({
389389
Logger: {
390-
verbose: (message) => {
391-
debugger;
392-
return verboseSpy(message);
393-
},
390+
verbose: (message) => verboseSpy(message),
394391
error: (message) => errorSpy(message),
395392
},
396393
_Helpers: {
@@ -628,7 +625,7 @@ describe('Identity Api Client', () => {
628625
expect(invokeCallbackSpy.args[0][1]).to.equal(-1);
629626
expect(invokeCallbackSpy.args[0][2]).to.equal("Received HTTP Code of 404");
630627

631-
// A 403 should not call parseIdentityResponse
628+
// A 404 should not call parseIdentityResponse
632629
expect(parseIdentityResponseSpy.calledOnce, 'parseIdentityResponseSpy').to.eq(false);
633630
});
634631

0 commit comments

Comments
 (0)