in src/server/lib/okta/idx/shared/idxFetch.ts [142:186]
function findErrorMessageRecursive(
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- This function is designed to handle any object
obj: any,
): IdxErrorObject | string | undefined {
// Check if obj is an object
if (typeof obj === 'object' && obj !== null) {
// If obj is an array
if (Array.isArray(obj)) {
// Iterate through each element of the array
for (const item of obj) {
// Recursively search each element
const result = findErrorMessageRecursive(item);
// If key is found, return the value
if (result !== undefined) {
return result;
}
}
} else {
// Iterate through each key-value pair in the object
for (const prop in obj) {
if (Object.prototype.hasOwnProperty.call(obj, prop)) {
// If key is found, return the value
if (prop === 'messages') {
const parsed = idxErrorObjectSchema.safeParse(obj[prop]);
if (parsed.success) {
return parsed.data;
} else {
return JSON.stringify(obj[prop]);
}
}
// Recursively search the value
const result = findErrorMessageRecursive(obj[prop]);
// If key is found in the nested object, return the value
if (result !== undefined) {
return result;
}
}
}
}
}
// Key not found, return undefined
return undefined;
}