Skip to content

Commit 4377e44

Browse files
authored
fix(property-provider): copy error properties to ProviderError in from() (#3440)
1 parent a79f962 commit 4377e44

File tree

3 files changed

+8
-15
lines changed

3 files changed

+8
-15
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
import { CredentialsProviderError } from "./CredentialsProviderError";
2+
import { ProviderError } from "./ProviderError";
23

34
describe(CredentialsProviderError.name, () => {
45
it("should be named as CredentialsProviderError", () => {
56
expect(new CredentialsProviderError("PANIC").name).toBe("CredentialsProviderError");
67
});
78

8-
describe("should be instanceof CredentialsProviderError", () => {
9+
describe.each([Error, ProviderError, CredentialsProviderError])("should be instanceof %p", (classConstructor) => {
910
it("when created using constructor", () => {
10-
expect(new CredentialsProviderError("PANIC")).toBeInstanceOf(CredentialsProviderError);
11+
expect(new CredentialsProviderError("PANIC")).toBeInstanceOf(classConstructor);
1112
});
1213

1314
it("when created using from()", () => {
14-
// ToDo: set instanceof to be CredentialsProviderError
15-
expect(CredentialsProviderError.from(new Error("PANIC"))).toBeInstanceOf(Error);
15+
expect(CredentialsProviderError.from(new Error("PANIC"))).toBeInstanceOf(classConstructor);
1616
});
1717
});
1818
});

packages/property-provider/src/ProviderError.spec.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,13 @@ describe(ProviderError.name, () => {
1313
expect(new ProviderError("PANIC", false).tryNextLink).toBe(false);
1414
});
1515

16-
describe("should be instanceof ProviderError", () => {
16+
describe.each([Error, ProviderError])("should be instanceof %p", (classConstructor) => {
1717
it("when created using constructor", () => {
18-
expect(new ProviderError("PANIC")).toBeInstanceOf(ProviderError);
18+
expect(new ProviderError("PANIC")).toBeInstanceOf(classConstructor);
1919
});
2020

2121
it("when created using from()", () => {
22-
// ToDo: set instanceof to be CredentialsProviderError
23-
expect(ProviderError.from(new Error("PANIC"))).toBeInstanceOf(Error);
22+
expect(ProviderError.from(new Error("PANIC"))).toBeInstanceOf(classConstructor);
2423
});
2524
});
2625

packages/property-provider/src/ProviderError.ts

+1-7
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,6 @@ export class ProviderError extends Error {
1313
super(message);
1414
}
1515
static from(error: Error, tryNextLink = true): ProviderError {
16-
Object.defineProperty(error, "tryNextLink", {
17-
value: tryNextLink,
18-
configurable: false,
19-
enumerable: false,
20-
writable: false,
21-
});
22-
return error as ProviderError;
16+
return Object.assign(new this(error.message, tryNextLink), error);
2317
}
2418
}

0 commit comments

Comments
 (0)