fix: improve error handling

- Do not throw in onError callback for server client. This lets the originating error bubble to Next.js.
- Do not log errors inside the service token procedure, server client onError callback will log all procedure errors.
- Log errors for fetching service token failure.
This commit is contained in:
Michael Zetterberg
2024-10-11 10:42:40 +02:00
parent 1bce311666
commit 7bbb8915b3
3 changed files with 65 additions and 49 deletions

View File

@@ -124,7 +124,7 @@ export const safeProtectedProcedure = t.procedure.use(async function (opts) {
export const serviceProcedure = t.procedure.use(async (opts) => {
const { access_token } = await getServiceToken()
if (!access_token) {
throw internalServerError(`Failed to obtain service token`)
throw internalServerError(`[serviceProcedure] No service token`)
}
return opts.next({
ctx: {
@@ -144,7 +144,9 @@ export const serviceServerActionProcedure = serverActionProcedure.use(
async (opts) => {
const { access_token } = await getServiceToken()
if (!access_token) {
throw internalServerError("Failed to obtain service token")
throw internalServerError(
"[serviceServerActionProcedure]: No service token"
)
}
return opts.next({
ctx: {