about summary refs log tree commit diff
path: root/src/lib/strings/errors.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/strings/errors.ts')
-rw-r--r--src/lib/strings/errors.ts23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/lib/strings/errors.ts b/src/lib/strings/errors.ts
new file mode 100644
index 000000000..0efcad335
--- /dev/null
+++ b/src/lib/strings/errors.ts
@@ -0,0 +1,23 @@
+export function cleanError(str: any): string {
+  if (!str) {
+    return ''
+  }
+  if (typeof str !== 'string') {
+    str = str.toString()
+  }
+  if (isNetworkError(str)) {
+    return 'Unable to connect. Please check your internet connection and try again.'
+  }
+  if (str.includes('Upstream Failure')) {
+    return 'The server appears to be experiencing issues. Please try again in a few moments.'
+  }
+  if (str.startsWith('Error: ')) {
+    return str.slice('Error: '.length)
+  }
+  return str
+}
+
+export function isNetworkError(e: unknown) {
+  const str = String(e)
+  return str.includes('Abort') || str.includes('Network request failed')
+}