Skip to content

Commit 1cbee39

Browse files
committed
Update getPreviousList to check Error.cause
We'll eventually want to migrate to this, as it is the standard now.
1 parent bf7c27b commit 1cbee39

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/common/exceptions/exception.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@ export const hasPrevious = (e: Error): e is Error & { previous: Error } =>
2929
export function getPreviousList(ex: Error, includeSelf: boolean) {
3030
const previous: Error[] = includeSelf ? [ex] : [];
3131
let current = ex;
32-
while (hasPrevious(current)) {
33-
current = current.previous;
32+
while (current.cause instanceof Error || hasPrevious(current)) {
33+
current = hasPrevious(current)
34+
? current.previous
35+
: (current.cause as Error);
3436
previous.push(current);
3537
}
3638
return previous;

0 commit comments

Comments
 (0)