Skip to content

Error codes

Every error this library throws carries a stable code (a TemplateErrorCode), extends a NestJS HTTP exception, and — for render failures — a structured details payload. Use the isTemplateError(err) guard to narrow.

codeClassHTTPWhen
TEMPLATE_RENDER_FAILEDTemplateRenderError422A template/layout failed to render (bad syntax, missing variable, language error). Carries the rich details.
TEMPLATE_NOT_FOUNDTemplateNotFoundError404The template/layout was not found in any scope or locale.
TEMPLATE_INVALID_INPUTTemplateInputError400Invalid call input (e.g. missing name/content).
TEMPLATE_FORBIDDENTemplateForbiddenError403Operation not permitted (e.g. mutating a system template).
TEMPLATE_CONFLICTTemplateConflictError409A template with the same identity already exists.
TEMPLATE_ENGINE_UNAVAILABLETemplateEngineUnavailableError500The engine is not enabled, or its peer package isn't installed.

details payload (render errors)

typescript
interface TemplateErrorDetails {
  code: TemplateErrorCode;
  message: string;
  stage?: 'subject' | 'template-engine' | 'language-engine' | 'layout';
  engine?: string;
  language?: string;
  templateName?: string;
  scope?: string;
  scopeId?: string;
  locale?: string;
  missingVariable?: string;
  contextKeys?: string[];
  location?: { line: number; column?: number };
  snippet?: string;
  hint?: string;
}

Narrowing

typescript
import { isTemplateError, TemplateErrorCode } from '@ackplus/nest-dynamic-templates';

catch (err) {
  if (isTemplateError(err) && err.code === TemplateErrorCode.RENDER_FAILED) {
    logger.warn('render failed', err.details);
  }
  throw err;
}

See the error handling guide for full examples and the JSON response shape.

Released under the MIT License.