Skip to content

Commit

Permalink
fix: auth0 error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Gauravudia committed May 2, 2024
1 parent 7b1d11b commit 2e22075
Show file tree
Hide file tree
Showing 2 changed files with 119 additions and 33 deletions.
16 changes: 5 additions & 11 deletions src/v0/sources/auth0/transform.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const path = require('path');
const fs = require('fs');
const { InstrumentationError } = require('@rudderstack/integrations-lib');
const { removeUndefinedAndNullValues } = require('../../util');
const { getGroupId } = require('./util');
// import mapping json using JSON.parse to preserve object key order
Expand Down Expand Up @@ -59,11 +58,10 @@ function processEvents(eventList) {
} else {
response = prepareTrackPayload(data);
}
if (response?.userId) {
// eslint-disable-next-line camelcase
response.properties.log_id = log_id;
responses.push(removeUndefinedAndNullValues(response));
}

// eslint-disable-next-line camelcase
response.properties.log_id = log_id;
responses.push(removeUndefinedAndNullValues(response));
}
});
return responses;
Expand All @@ -74,11 +72,7 @@ function process(events) {
if (!Array.isArray(events)) {
eventList = events.logs || [events];
}
const responses = processEvents(eventList);
if (responses.length === 0) {
throw new InstrumentationError('UserId is not present');
}
return responses;
return processEvents(eventList);
}

exports.process = process;
136 changes: 114 additions & 22 deletions test/__tests__/data/auth0_source.json
Original file line number Diff line number Diff line change
Expand Up @@ -1147,18 +1147,51 @@
"log_id": "90020221031055712103169676686005480714681762668315934738"
}
},
"output": {
"statusCode": 400,
"error": "UserId is not present",
"statTags": {
"errorCategory": "dataValidation",
"errorType": "instrumentation",
"module": "source",
"implementation": "native",
"destinationId": "Non determinable",
"workspaceId": "Non determinable"
"output": [
{
"type": "identify",
"sentAt": "2022-10-31T05:57:06.859Z",
"traits": {
"connection": "Username-Password-Authentication",
"connection_id": "con_djwCjiwyID0vZy1S"
},
"userId": "",
"context": {
"traits": {
"userId": "",
"user_name": "[email protected]"
},
"library": {
"name": "unknown",
"version": "unknown"
},
"userAgent": "unknown",
"request_ip": "35.166.202.113",
"integration": {
"name": "Auth0"
}
},
"properties": {
"log_id": "90020221031055712103169676686005480714681762668315934738",
"details": {
"body": {
"email": "[email protected]",
"tenant": "dev-cu4jy2zgao6yx15x",
"password": "dummyPassword",
"client_id": "vQcJNDTxsM1W72eHFonRJdzyOvawlwIt",
"connection": "Username-Password-Authentication"
}
},
"client_id": "vQcJNDTxsM1W72eHFonRJdzyOvawlwIt",
"client_name": "All Applications",
"description": ""
},
"integrations": {
"Auth0": false
},
"originalTimestamp": "2022-10-31T05:57:06.859Z"
}
}
]
},
{
"description": "UserId is missing for all the requests in a batch",
Expand Down Expand Up @@ -1205,17 +1238,76 @@
}
}
],
"output": {
"statusCode": 400,
"error": "UserId is not present",
"statTags": {
"errorCategory": "dataValidation",
"errorType": "instrumentation",
"module": "source",
"implementation": "native",
"destinationId": "Non determinable",
"workspaceId": "Non determinable"
"output": [
{
"type": "identify",
"userId": "",
"sentAt": "2022-10-31T05:57:06.859Z",
"traits": {
"connection": "Username-Password-Authentication",
"connection_id": "con_djwCjiwyID0vZy1S"
},
"context": {
"traits": {
"userId": "",
"user_name": "[email protected]"
},
"library": {
"name": "unknown",
"version": "unknown"
},
"userAgent": "unknown",
"request_ip": "35.166.202.113",
"integration": {
"name": "Auth0"
}
},
"properties": {
"log_id": "90020221031055712103169676686005480714681762668315934738",
"details": {
"body": {
"email": "[email protected]",
"tenant": "dev-cu4jy2zgao6yx15x",
"password": "dummyPassword",
"client_id": "vQcJNDTxsM1W72eHFonRJdzyOvawlwIt",
"connection": "Username-Password-Authentication"
}
},
"client_id": "vQcJNDTxsM1W72eHFonRJdzyOvawlwIt",
"client_name": "All Applications",
"description": ""
},
"integrations": {
"Auth0": false
},
"originalTimestamp": "2022-10-31T05:57:06.859Z"
},
{
"type": "track",
"event": "Success API Operation",
"sentAt": "2022-10-31T05:57:06.874Z",
"context": {
"library": {
"name": "unknown",
"version": "unknown"
},
"userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36",
"request_ip": "35.166.202.113",
"integration": {
"name": "Auth0"
}
},
"properties": {
"log_id": "90020221031055712103169676686007898566320991926665347090",
"client_id": "vQcJNDTxsM1W72eHFonRJdzyOvawlwIt",
"client_name": "",
"description": "Create a User"
},
"integrations": {
"Auth0": false
},
"originalTimestamp": "2022-10-31T05:57:06.874Z"
}
}
]
}
]

0 comments on commit 2e22075

Please sign in to comment.