Reference

Error Handling

Error handling in dnax Framework.

dnax Framework provides a standardized error handling system.

AppError Class

import { AppError, fn } from '@dnax/core';

throw new AppError('Something went wrong', {
  code: 'CUSTOM_ERROR',
  status: 400,
  meta: { details: '...' }
});

Error Response Format

All errors return a consistent JSON format:

{
  "message": "Error description",
  "code": "ERROR_CODE",
  "meta": {}
}

Built-in Error Codes

CodeStatusDescription
TENANT_ID_REQUIRED400Missing tenant_id
COLLECTION_REQUIRED400Missing collection
ACTION_REQUIRED400Missing action
INVALID_JSON_BODY400Invalid JSON body
TENANT_NOT_FOUND400Tenant not found
COLLECTION_NOT_FOUND400Collection not found
ACTION_NOT_FOUND400Action not found
AUTH_NOT_ENABLED400Auth not enabled
AUTH_HANDLER_NOT_DEFINED400Auth handler missing
INVALID_TOKEN_ASSIGNED401Invalid token
INVALID_TOKEN401JWT invalid
ACCESS_DENIED401Access denied
VALIDATION_ERROR400Schema validation
INTERNAL_SERVER_ERROR500Internal error

Throw Custom Errors

In custom actions:

actions: {
  myAction: async ({ data, error }) => {
    if (!data.required) {
      throw error('Field required', {
        code: 'REQUIRED_FIELD',
        status: 400,
      });
    }
  },
}

Global Error Handler

Errors are automatically caught and formatted:

try {
  // API logic
} catch (err) {
  const isAppError = err instanceof AppError;
  return c.json({
    message: isAppError ? err.message : 'Internal server error',
    code: isAppError ? err.code : 'INTERNAL_SERVER_ERROR',
    meta: isAppError ? err.meta : undefined,
  }, isAppError ? err.status : 500);
}
Copyright © 2026