Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: error handling for auth0 source #3038

Merged
merged 7 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/v0/sources/auth0/transform.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
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 @@ -73,7 +74,11 @@ function process(events) {
if (!Array.isArray(events)) {
eventList = events.logs || [events];
}
return processEvents(eventList);
const responses = processEvents(eventList);
if (responses.length === 0) {
throw new InstrumentationError('UserId is not present');
}
return responses;
}

exports.process = process;
2 changes: 1 addition & 1 deletion test/__tests__/auth0_source.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ testData.forEach((data, index) => {
const output = transformer.process(data.input);
expect(output).toEqual(data.output);
} catch (error) {
expect(error.message).toEqual(data.output.message);
expect(error.message).toEqual(data.output.error);
}
});
});
101 changes: 101 additions & 0 deletions test/__tests__/data/auth0_source.json
Original file line number Diff line number Diff line change
Expand Up @@ -1116,5 +1116,106 @@
"originalTimestamp": "2022-10-31T06:15:25.196Z"
}
]
},
{
"description": "Missing userId",
"input": {
"log_id": "90020221031055712103169676686005480714681762668315934738",
"data": {
"date": "2022-10-31T05:57:06.859Z",
"type": "ss",
"description": "",
"connection": "Username-Password-Authentication",
"connection_id": "con_djwCjiwyID0vZy1S",
"client_id": "vQcJNDTxsM1W72eHFonRJdzyOvawlwIt",
"client_name": "All Applications",
"ip": "35.166.202.113",
"user_agent": "unknown",
"details": {
"body": {
"email": "[email protected]",
"tenant": "dev-cu4jy2zgao6yx15x",
"password": "dummyPassword",
"client_id": "vQcJNDTxsM1W72eHFonRJdzyOvawlwIt",
"connection": "Username-Password-Authentication"
}
},
"user_id": "",
"user_name": "[email protected]",
"strategy": "auth0",
"strategy_type": "database",
"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"
}
}
},
{
"description": "UserId is missing for all the requests in a batch",
"input": [
{
"log_id": "90020221031055712103169676686005480714681762668315934738",
"data": {
"date": "2022-10-31T05:57:06.859Z",
"type": "ss",
"description": "",
"connection": "Username-Password-Authentication",
"connection_id": "con_djwCjiwyID0vZy1S",
"client_id": "vQcJNDTxsM1W72eHFonRJdzyOvawlwIt",
"client_name": "All Applications",
"ip": "35.166.202.113",
"user_agent": "unknown",
"details": {
"body": {
"email": "[email protected]",
"tenant": "dev-cu4jy2zgao6yx15x",
"password": "dummyPassword",
"client_id": "vQcJNDTxsM1W72eHFonRJdzyOvawlwIt",
"connection": "Username-Password-Authentication"
}
},
"user_id": "",
"user_name": "[email protected]",
"strategy": "auth0",
"strategy_type": "database",
"log_id": "90020221031055712103169676686005480714681762668315934738"
}
},
{
"log_id": "90020221031055712103169676686007898566320991926665347090",
"data": {
"date": "2022-10-31T05:57:06.874Z",
"type": "sapi",
"description": "Create a User",
"client_id": "vQcJNDTxsM1W72eHFonRJdzyOvawlwIt",
"client_name": "",
"ip": "35.166.202.113",
"user_agent": "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",
"log_id": "90020221031055712103169676686007898566320991926665347090"
}
}
],
"output": {
"statusCode": 400,
"error": "UserId is not present",
"statTags": {
"errorCategory": "dataValidation",
"errorType": "instrumentation",
"module": "source",
"implementation": "native",
"destinationId": "Non determinable",
"workspaceId": "Non determinable"
}
}
}
]
Loading