summaryrefslogtreecommitdiff
path: root/packages/taler-util/src/helpers.ts
diff options
context:
space:
mode:
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..d4c3c86b5 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}>`;
+}