Skip to content

Commit

Permalink
fix(analytics): correctly extract statusCode from failed request (#5618)
Browse files Browse the repository at this point in the history
  • Loading branch information
iartemiev committed Apr 29, 2020
1 parent f5db38d commit e11e938
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
Expand Up @@ -736,7 +736,9 @@ describe('AnalyticsProvider test', () => {
test('Exceeded maximum endpoint per user count', async () => {
const analytics = new AnalyticsProvider();
const mockExceededMaxError = {
statusCode: 400,
$metadata: {
httpStatusCode: 400,
},
message: 'Exceeded maximum endpoint per user count 10',
};

Expand Down
6 changes: 4 additions & 2 deletions packages/analytics/src/Providers/AWSPinpointProvider.ts
Expand Up @@ -431,8 +431,9 @@ export class AWSPinpointProvider implements AnalyticsProvider {

private async _handleEndpointUpdateFailure(failureData: EndpointFailureData) {
const { err, endpointObject } = failureData;
const { statusCode } = err;
logger.debug('updateEndpoint failed', err);
const statusCode = err.$metadata && err.$metadata.httpStatusCode;

logger.error('updateEndpoint failed', err);

switch (statusCode) {
case BAD_REQUEST_CODE:
Expand Down Expand Up @@ -482,6 +483,7 @@ export class AWSPinpointProvider implements AnalyticsProvider {

private _handleEndpointUpdateForbidden(failureData: EndpointFailureData) {
const { err, endpointObject } = failureData;

const { code, retryable } = err;

if (code !== EXPIRED_TOKEN_CODE && !retryable) {
Expand Down
4 changes: 2 additions & 2 deletions packages/analytics/src/Providers/EventBuffer.ts
Expand Up @@ -150,8 +150,8 @@ export default class EventsBuffer {
}

private _handlePutEventsFailure(err, eventMap: EventMap) {
logger.debug('_putEvents Failed:', err);
const { statusCode } = err;
logger.error('_putEvents Failed: ', err);
const statusCode = err.$metadata && err.$metadata.httpStatusCode;

if (RETRYABLE_CODES.includes(statusCode)) {
const retryableEvents = Object.values(eventMap);
Expand Down

0 comments on commit e11e938

Please sign in to comment.