Skip to content

Commit 20802bd

Browse files
feat: log verbose errors to the console if a query fails
1 parent f115564 commit 20802bd

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

docs/config/index.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,16 @@ interface ModuleOptions {
123123
* @default 1
124124
*/
125125
maxAge?: number
126+
127+
/**
128+
* Log verbose errors to the console if a query fails
129+
*
130+
* @remarks
131+
* This will log the full query to the console, which may contain sensitive data.
132+
*
133+
* @default false
134+
*/
135+
verboseErrors?: boolean
126136
}
127137
}
128138
```

src/module.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,16 @@ export interface ModuleOptions {
109109
* @default 1
110110
*/
111111
maxAge?: number
112+
113+
/**
114+
* Log verbose errors to the console if a query fails
115+
*
116+
* @remarks
117+
* This will log the full query to the console, which may contain sensitive data.
118+
*
119+
* @default false
120+
*/
121+
verboseErrors?: boolean
112122
}
113123
}
114124

@@ -136,6 +146,7 @@ export default defineNuxtModule<ModuleOptions>({
136146
storage: 'cache',
137147
swr: false,
138148
maxAge: 1,
149+
verboseErrors: false,
139150
},
140151
},
141152
async setup(options, nuxt) {

src/runtime/server/handler.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { consola } from 'consola'
12
import { createError, defineEventHandler, getRouterParam, readBody } from 'h3'
23
import type { ModuleOptions } from '../../module'
34
import { createAuthHeader } from '../utils'
@@ -42,6 +43,12 @@ async function fetcher({
4243
return result
4344
}
4445
catch (err) {
46+
if (kql.server.verboseErrors) {
47+
if (isQueryRequest)
48+
consola.error('Failed to execute KQL query:', query)
49+
else consola.error(`Failed to fetch "${path}" with options:`, { headers, method, query, body })
50+
}
51+
4552
throw createError({
4653
statusCode: 500,
4754
statusMessage: isQueryRequest

0 commit comments

Comments
 (0)