js4j 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/exceptions.js +15 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "js4j",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "A Node.js implementation of py4j — bridge between JavaScript and Java via the Py4J gateway protocol",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
package/src/exceptions.js CHANGED
@@ -33,6 +33,21 @@ class Js4JJavaError extends Js4JError {
33
33
  this.javaException = javaException || null;
34
34
  }
35
35
 
36
+ /**
37
+ * Fetch the human-readable Java exception message by calling getMessage()
38
+ * on the Java Throwable object. Falls back to the raw protocol payload
39
+ * (javaExceptionMessage) if the Java call fails or javaException is null.
40
+ * @returns {Promise<string>}
41
+ */
42
+ async getJavaMessage() {
43
+ if (!this.javaException) return this.javaExceptionMessage || this.message;
44
+ try {
45
+ return await this.javaException.getMessage();
46
+ } catch (_) {
47
+ return this.javaExceptionMessage || this.message;
48
+ }
49
+ }
50
+
36
51
  toString() {
37
52
  return `${this.name}: ${this.message}\n Java exception payload: ${this.javaExceptionMessage}`;
38
53
  }