feat(#27): Set up consola logger, make use of log levels in backend and frontend

This commit is contained in:
2025-12-24 10:26:22 +01:00
parent 805c66bc4f
commit 7f7852a66a
36 changed files with 312 additions and 141 deletions

View File

@@ -1,12 +1,14 @@
import { defineStore } from 'pinia'
import { type CreateCommentDto, type CommentDto, ResponseError } from '~~/.api-client'
import { useCommentApi } from '~/composables/comment/useCommentApi'
import { useLogger } from '../app/composables/useLogger'
export const useCommentStore = defineStore('Comment', () => {
type FormElementId = string
const commentApi = useCommentApi()
const comments = ref<Record<FormElementId, CommentDto[]>>({})
const loadedForms = ref(new Set<string>())
const logger = useLogger().withTag('commentStore')
async function load(applicationFormId: string) {
if (loadedForms.value.has(applicationFormId)) return
@@ -14,7 +16,7 @@ export const useCommentStore = defineStore('Comment', () => {
commentApi.getCommentsByApplicationFormId(applicationFormId)
)
if (error.value) {
console.error('Failed loading comments:', error.value)
logger.error('Failed loading comments:', error.value)
return
}
comments.value =
@@ -43,9 +45,9 @@ export const useCommentStore = defineStore('Comment', () => {
return newComment
} catch (e: unknown) {
if (e instanceof ResponseError) {
console.error('Failed creating comment:', e.response)
logger.error('Failed creating comment:', e.response)
} else {
console.error('Failed creating comment:', e)
logger.error('Failed creating comment:', e)
}
return Promise.reject(e)
}
@@ -69,9 +71,9 @@ export const useCommentStore = defineStore('Comment', () => {
return updatedComment
} catch (e: unknown) {
if (e instanceof ResponseError) {
console.error(`Failed updating comment with ID ${id}:`, e.response)
logger.error(`Failed updating comment with ID ${id}:`, e.response)
} else {
console.error(`Failed updating comment with ID ${id}:`, e)
logger.error(`Failed updating comment with ID ${id}:`, e)
}
return Promise.reject(e)
}
@@ -92,9 +94,9 @@ export const useCommentStore = defineStore('Comment', () => {
}
} catch (e: unknown) {
if (e instanceof ResponseError) {
console.error(`Failed deleting comment with ID ${id}:`, e.response)
logger.error(`Failed deleting comment with ID ${id}:`, e.response)
} else {
console.error(`Failed deleting comment with ID ${id}:`, e)
logger.error(`Failed deleting comment with ID ${id}:`, e)
}
return Promise.reject(e)
}