aboutsummaryrefslogtreecommitdiff
path: root/packages/taler-util/src/helpers.ts
diff options
context:
space:
mode:
authorFlorian Dold <florian@dold.me>2023-01-02 21:00:43 +0100
committerFlorian Dold <florian@dold.me>2023-01-02 21:00:43 +0100
commitd48ea17c6345abaa732deb5fab6141449d463e41 (patch)
tree8983639bb6441965fd5d77b742409c87b9497797 /packages/taler-util/src/helpers.ts
parent13d6810937255a136dcd098d142037cfb143a34e (diff)
downloadwallet-core-d48ea17c6345abaa732deb5fab6141449d463e41.tar.xz
-logging, skip defaults in test
Diffstat (limited to 'packages/taler-util/src/helpers.ts')
-rw-r--r--packages/taler-util/src/helpers.ts16
1 files changed, 16 insertions, 0 deletions
diff --git a/packages/taler-util/src/helpers.ts b/packages/taler-util/src/helpers.ts
index 7d84d434e..95c6bf286 100644
--- a/packages/taler-util/src/helpers.ts
+++ b/packages/taler-util/src/helpers.ts
@@ -121,3 +121,19 @@ export function j2s(x: any): string {
export function notEmpty<T>(value: T | null | undefined): value is T {
return value !== null && value !== undefined;
}
+
+/**
+ * Safe function to stringify errors.
+ */
+export function stringifyError(x: any): string {
+ if (typeof x === "undefined") {
+ return "<thrown undefined>";
+ }
+ if (x === null) {
+ return `<thrown null>`;
+ }
+ if (typeof x === "object") {
+ return x.toString();
+ }
+ return `<thrown ${typeof x}>`;
+} \ No newline at end of file