Skip to content

Commit

Permalink
fix: error handling for auth0 source (#3038)
Browse files Browse the repository at this point in the history
* fix: error handling for auth0 source

* chore: clear redundant testcase data

* refactor: error message

* test: add testcases

---------

Co-authored-by: chandumlg <[email protected]>
  • Loading branch information
Gauravudia and chandumlg authored Feb 6, 2024
1 parent c7c3110 commit 2a21274
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 2 deletions.
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"
}
}
}
]

0 comments on commit 2a21274

Please sign in to comment.