Skip to content

Commit 95c6e5d

Browse files
kushalshit27mgyarmathy
authored andcommitted
fix: handle responses when paginating custom domains (auth0#1214)
* Update CHANGELOG * 8.20.3 * fix(client.ts): improve getEntity function to handle various response types - Update getEntity to accept ApiResponse or Asset[] as input - Return empty array for empty responses instead of throwing an error - Directly return response if it is an array
1 parent 81ed1e7 commit 95c6e5d

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/tools/auth0/client.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,21 @@ const API_FREQUENCY_PER_SECOND = 8;
1818

1919
const MAX_PAGE_SIZE = 100;
2020

21-
function getEntity(rsp: ApiResponse): Asset[] {
21+
function getEntity(rsp: ApiResponse | Asset[]): Asset[] {
22+
// Extract all array values from the response object
2223
const found = Object.values(rsp).filter((a) => Array.isArray(a));
24+
25+
// If response contains exactly one array property, return it as the entity list
2326
if (Array.isArray(found) && found.length === 1) {
2427
return found[0] as Asset[];
2528
}
26-
// Handle empty response case - return empty array instead of throwing error
29+
30+
// If the response itself is an array, return it directly
31+
if (Array.isArray(rsp)) {
32+
return rsp as Asset[];
33+
}
34+
35+
// If empty response case - return empty array instead of throwing error
2736
if (Array.isArray(found) && found.length === 0) {
2837
return [];
2938
}

0 commit comments

Comments
 (0)