Skip to content

Commit cb5bc36

Browse files
committed
feat: ffi: ts: adjust CoreCryptoError WIP
1 parent 9b402fe commit cb5bc36

File tree

1 file changed

+13
-18
lines changed

1 file changed

+13
-18
lines changed

crypto-ffi/bindings/js/src/CoreCryptoError.ts

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { CoreCryptoError_Tags, CoreCryptoError as CoreCryptoErrorFfi } from "./index.web";
2+
13
/**
24
* The error structure produced by our rust code.
35
**/
@@ -24,25 +26,18 @@ export class CoreCryptoError<T extends ErrorType> extends Error {
2426
type?: T;
2527

2628
/* eslint @typescript-eslint/no-explicit-any: off */
27-
private constructor(richError: CoreCryptoRichError<T>, ...params: any[]) {
28-
super(richError.message, ...params);
29-
Object.setPrototypeOf(this, new.target.prototype);
30-
31-
if (richError.error_name) {
32-
this.name = richError.error_name;
33-
}
34-
if (richError.error_stack) {
35-
this.errorStack = richError.error_stack;
29+
private constructor(richError: unknown ) {
30+
if (CoreCryptoErrorFfi.instanceOf(richError)) {
31+
switch (richError.tag) {
32+
case CoreCryptoError_Tags.E2ei: {
33+
super(richError.message)
34+
this.errorStack = []
35+
this.context = {e2eiError: richError.inner.e2eiError}
36+
this.type = ErrorType.E2ei
37+
}
38+
}
3639
} else {
37-
this.errorStack = [];
38-
}
39-
if (
40-
richError.context &&
41-
richError.type &&
42-
Object.values<string>(ErrorType).includes(richError.type)
43-
) {
44-
this.context = richError.context;
45-
this.type = richError.type as T;
40+
throw Error("Unexpected error instance. Context: constructing CoreCryptoError.")
4641
}
4742
}
4843

0 commit comments

Comments
 (0)