You've already forked AstralRinth
forked from xxxOFFxxx/AstralRinth
* feat: base api-client impl * fix: doc * feat: start work on module stuff * feat: migrate v2/v3 projects into module system * fix: lint & README.md contributing * refactor: remove utils old api client prototype * fix: lint * fix: api url issues * fix: baseurl in error.vue * fix: readme * fix typo in readme * Update apps/frontend/src/providers/api-client.ts Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Calum H. <hendersoncal117@gmail.com> * Update packages/api-client/src/features/verbose-logging.ts Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Calum H. <hendersoncal117@gmail.com> * Update packages/api-client/src/features/retry.ts Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Calum H. <hendersoncal117@gmail.com> --------- Signed-off-by: Calum H. <hendersoncal117@gmail.com> Co-authored-by: Prospector <6166773+Prospector@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
31 lines
947 B
TypeScript
31 lines
947 B
TypeScript
import { AbstractFeature, type FeatureConfig } from '../core/abstract-feature'
|
|
import type { RequestContext } from '../types/request'
|
|
|
|
export type VerboseLoggingConfig = FeatureConfig
|
|
|
|
export class VerboseLoggingFeature extends AbstractFeature {
|
|
async execute<T>(next: () => Promise<T>, context: RequestContext): Promise<T> {
|
|
const method = context.options.method ?? 'GET'
|
|
const api = context.options.api
|
|
const version = context.options.version
|
|
const prefix = `[${method}] [${api}_v${version}]`
|
|
|
|
console.debug(`${prefix} ${context.url} SENT`)
|
|
|
|
try {
|
|
const result = await next()
|
|
try {
|
|
const size = result ? JSON.stringify(result).length : 0
|
|
console.debug(`${prefix} ${context.url} RECEIVED ${size} bytes`)
|
|
} catch {
|
|
// ignore size calc fail
|
|
console.debug(`${prefix} ${context.url} RECEIVED`)
|
|
}
|
|
return result
|
|
} catch (error) {
|
|
console.debug(`${prefix} ${context.url} FAILED`)
|
|
throw error
|
|
}
|
|
}
|
|
}
|