Skip to content

Commit

Permalink
Add better API logging
Browse files Browse the repository at this point in the history
  • Loading branch information
zobweyt committed Aug 8, 2024
1 parent 07f60e9 commit d1fe125
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion frontend/src/lib/api/middleware.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { type Middleware } from "openapi-fetch";
import colors from "picocolors";
import { getSession, resetSession } from "~/lib/auth/session";

export const AUTH_MIDDLEWARE: Middleware = {
Expand All @@ -19,6 +20,12 @@ export const AUTH_MIDDLEWARE: Middleware = {

export const DEBUG_MIDDLEWARE: Middleware = {
onResponse: (options) => {
console.debug(`${options.request.method} ${options.schemaPath} - ${options.response.status} ${options.response.statusText}`);
const timestamp = colors.dim(new Date().toLocaleTimeString());
const prefix = colors.cyan(colors.bold("[api]"));
const method = colors.green(options.request.method);
const route = colors.dim(options.request.url);
const status = colors.yellow(`${options.response.status} ${options.response.statusText}`);

console.debug(`${timestamp} ${prefix} ${method} ${route} ${status}`);
},
};

0 comments on commit d1fe125

Please sign in to comment.