Skip to content

armgit / TREK

Public Imported from GitHub
0

The most complete open-source travel planner: real-time collaboration, bookings, budgets, packing lists, journals, offline PWA, SSO and an AI-ready MCP server, with planet-wide place search and routing built in.

834 B
Raw Blame
import { DomainError } from '../../src/nest/common/domain-error';

/**
 * Awaits a service call and hands a `DomainError` refusal back as the
 * `{ error, status }` result the service used to return, so a test can assert a
 * refusal and a success through one shape. Any other rejection propagates.
 */
export async function asLegacyResult<T>(call: Promise<T> | T): Promise<T & { error?: string; status?: number }> {
  try {
    // A call that resolves to nothing (a void write) reads as the empty success it used to return.
    return ((await call) ?? {}) as T & { error?: string; status?: number };
  } catch (err) {
    if (err instanceof DomainError) {
      return { ...err.details, error: err.publicMessage, status: err.getStatus() } as T & {
        error?: string;
        status?: number;
      };
    }
    throw err;
  }
}