Skip to content

Errors

The package exposes DataSubjectError with stable error codes. Branch on err.code, not on the message.

Currently emitted codes

CodeMeaning
dsr_invalid_policyPolicy failed compilation (missing subjectField, unknown strategy, etc.)
dsr_anonymize_dynamic_replacementAn anonymize field used a function replacement — only static strings are allowed
dsr_verification_failedAfter a delete-row, residual rows were found for the subject
dsr_entity_already_registeredTwo entities registered with the same entityName
dsr_request_conflictA conflicting request already exists for the same subject
dsr_request_not_foundgetRequest(id) was called with an unknown id

When they surface

  • Boot timedsr_invalid_policy, dsr_anonymize_dynamic_replacement, dsr_entity_already_registered. Misconfigurations fail fast during module init, not mid-DSR.
  • Request submissiondsr_request_conflict when you try to create a second active request for the same subject.
  • Request executiondsr_verification_failed after erase if residual rows remain.
  • Lookupdsr_request_not_found from getRequest.

Pattern

ts
import { DataSubjectError } from '@nestarc/data-subject';

try {
  await dataSubject.erase('user_123', 'tenant_abc');
} catch (err) {
  if (err instanceof DataSubjectError) {
    if (err.code === 'dsr_request_conflict') {
      return existingRequest;
    }
    logger.error({ code: err.code }, 'DSR failed');
  }
  throw err;
}

Reserved codes

Additional codes exist in the public enum for future or adapter-specific use. Consumers should tolerate unknown codes when pattern-matching — treat anything outside the list above as an unexpected failure and surface it through your generic error path.

Released under the MIT License.