Skip to content

debug fn response

awekrx edited this page May 29, 2026 · 1 revision

debug-fn-response

Import

import { debugFnResponse } from '@dev-suite/decorators/debug-fn-response'

Category

  • method

Use Case

Log method response/error consistently for diagnostics.

Replaces

  • Inline response logging and try/catch console blocks
  • Different log shape in each method

Example 1

Without decorator

class SyncService {
  async sync() {
    try {
      const result = await this.engine.sync();
      console.log('sync result', result);
      return result;
    } catch (error) {
      console.error('sync error', error);
      throw error;
    }
  }
}

With decorator

import { debugFnResponse } from '@dev-suite/decorators/debug-fn-response';

class SyncService {
  @debugFnResponse({ label: 'sync.run' })
  async sync() {
    return this.engine.sync();
  }
}

Why better

  • Response/error logging is centralized and consistent.
  • Method logic remains focused on workflow.

Example 2

Without decorator

class ExportService {
  async export(id: string) {
    const data = await this.repo.load(id);
    console.log('export size', data.length);
    return data;
  }
}

With decorator

import { debugFnResponse } from '@dev-suite/decorators/debug-fn-response';

class ExportService {
  @debugFnResponse({ formatResponse: (data: Uint8Array) => ({ bytes: data.length }) })
  async export(id: string) {
    return this.repo.load(id);
  }
}

Why better

  • Can log summarized response shape safely.
  • Removes repetitive size/debug statements.

Clone this wiki locally