Skip to content

Commit c6f11c5

Browse files
committed
fix(android): wrap native errors in js Error
1 parent 18eb350 commit c6f11c5

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/https/request.android.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,16 @@ interface Ipeer {
1313
certificate?: string;
1414
x509Certificate?: java.security.cert.Certificate;
1515
}
16-
16+
function wrapJavaException(ex) {
17+
if (ex instanceof java.lang.Exception) {
18+
const err = new Error(ex.toString());
19+
err['nativeException'] = ex;
20+
//@ts-ignore
21+
err['stackTrace'] = com.tns.NativeScriptException.getStackTraceAsString(ex);
22+
return err;
23+
}
24+
return ex;
25+
}
1726
const peer: Ipeer = {
1827
enabled: false,
1928
allowInvalidCertificates: false,
@@ -612,13 +621,13 @@ export function createRequest(opts: HttpsRequestOptions, useLegacy: boolean = tr
612621
} catch (error) {
613622
console.error(error);
614623
delete runningClients[tag];
615-
reject(error);
624+
reject(wrapJavaException(error));
616625
}
617626
},
618627
onFailure(task, error) {
619628
console.error(error);
620629
delete runningClients[tag];
621-
reject(error);
630+
reject(wrapJavaException(error));
622631
}
623632
})
624633
);

0 commit comments

Comments
 (0)