@falcondev-oss/nuxt-layers-base 0.37.0 → 0.37.1
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.
- package/app/utils/plugins.ts +13 -3
- package/package.json +1 -1
package/app/utils/plugins.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { DehydratedState, QueryClientConfig, VueQueryPluginOptions } from '@tanstack/vue-query'
|
|
2
2
|
import type { OperationLink, TRPCClientError, TRPCLink } from '@trpc/client'
|
|
3
|
-
import type { AnyTRPCRouter, TRPCDefaultErrorData } from '@trpc/server'
|
|
3
|
+
import type { AnyTRPCRouter, TRPC_ERROR_CODE_KEY, TRPCDefaultErrorData } from '@trpc/server'
|
|
4
4
|
import type { FetchOptions } from 'ofetch'
|
|
5
5
|
import type { ObjectPlugin } from '#app'
|
|
6
6
|
import type { ToastOptions } from '../composables/useToast'
|
|
@@ -85,16 +85,26 @@ function isSchemaIssueList(message: string) {
|
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
+
const errorTitles: Partial<Record<TRPC_ERROR_CODE_KEY, string>> = {
|
|
89
|
+
BAD_REQUEST: 'Ungültige Eingabe',
|
|
90
|
+
UNAUTHORIZED: 'Nicht angemeldet',
|
|
91
|
+
FORBIDDEN: 'Kein Zugriff',
|
|
92
|
+
NOT_FOUND: 'Nicht vorhanden',
|
|
93
|
+
}
|
|
94
|
+
|
|
88
95
|
function requestErrorToast(err: unknown): ToastOpts {
|
|
89
96
|
if (isNetworkError(err))
|
|
90
97
|
return { title: 'Keine Verbindung', description: 'Der Server ist nicht erreichbar.' }
|
|
91
98
|
|
|
92
99
|
if (!isTRPCClientError<AnyTRPCRouter>(err)) return { title: 'Unbekannter Fehler' }
|
|
93
100
|
|
|
94
|
-
|
|
101
|
+
// internal errors leak implementation details and mean nothing to the user
|
|
102
|
+
if (errorData(err)?.httpStatus === 500) return { title: 'Server-Fehler' }
|
|
103
|
+
|
|
104
|
+
const code = errorData(err)?.code
|
|
95
105
|
|
|
96
106
|
return {
|
|
97
|
-
title:
|
|
107
|
+
title: (code && errorTitles[code]) ?? 'Anfrage-Fehler',
|
|
98
108
|
description: isSchemaIssueList(err.message) ? 'Bitte Eingaben überprüfen.' : err.message,
|
|
99
109
|
}
|
|
100
110
|
}
|