Skip to content

fix: catch feature_not_enabled via err.body.errorCode and 400 status in organizations handler - #1482

Open
harshithRai wants to merge 2 commits into
masterfrom
DXCDT-2295
Open

fix: catch feature_not_enabled via err.body.errorCode and 400 status in organizations handler#1482
harshithRai wants to merge 2 commits into
masterfrom
DXCDT-2295

Conversation

@harshithRai

Copy link
Copy Markdown
Contributor

🔧 Changes

Organization export/import could fail on tenants without the org-to-app or discovery-domains entitlement. The handler tried to swallow the feature_not_enabled error but the guard was wrong in two ways:

  • It read the error code from err.errorCode, which is always undefined. The auth0 SDK v6.3.0 ManagementError exposes the API code at err.body.errorCode, not err.errorCode.
  • It only matched HTTP 403. Some tenants now return 400 for feature_not_enabled, so the check missed those entirely.

With both conditions failing, the error was rethrown and aborted the run during processChanges (which calls getType first).

This adds a small isFeatureNotEnabled(err) helper that reads the code from err.body.errorCode and matches it regardless of HTTP status (400 or 403). Both catch blocks in the organizations handler (org-client associations and discovery domains) now use it and skip the unavailable data gracefully with a debug log instead of failing.

No data-shape changes: no config schema, JSON, or YAML output formats were modified. Behavior change is limited to error handling on unentitled tenants.

🔬 Testing

  • Added a unit test reproducing the reported failure: a 400 whose code lives on err.body.errorCode. It fails against the previous code and passes with the fix.
  • Ran the full non-e2e suite in chunks: 654 handler tests, plus context, tools, root, and command suites all pass; tsc and eslint clean.
  • Verified live against a dev tenant (export, read-only) that has organizations and does not have the org-to-app entitlement. Before the fix this export threw feature_not_enabled; after the fix it completes with exit 0, logs "Org-to-app entitlement is not enabled for this tenant. Skipping org-client associations." once per org, and still exports the organizations.

📝 Checklist

  • All new/changed/fixed functionality is covered by tests (or N/A)
  • I have added documentation for all new/changed functionality (or N/A)

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 33.33333% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.82%. Comparing base (4955e4b) to head (dc386b8).

Files with missing lines Patch % Lines
src/tools/auth0/handlers/organizations.ts 33.33% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1482   +/-   ##
=======================================
  Coverage   80.81%   80.82%           
=======================================
  Files         163      163           
  Lines        7805     7806    +1     
  Branches     1741     1742    +1     
=======================================
+ Hits         6308     6309    +1     
  Misses        797      797           
  Partials      700      700           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@harshithRai
harshithRai marked this pull request as ready for review September 3, 2026 07:43
@harshithRai
harshithRai requested a review from a team as a code owner September 3, 2026 07:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants