Skip to content

fix: make FgaApiAuthenticationError inherit from FgaApiError#327

Open
aaguiarz wants to merge 3 commits intomainfrom
fix/issue-326-auth-error-inheritance
Open

fix: make FgaApiAuthenticationError inherit from FgaApiError#327
aaguiarz wants to merge 3 commits intomainfrom
fix/issue-326-auth-error-inheritance

Conversation

@aaguiarz
Copy link
Member

@aaguiarz aaguiarz commented Feb 16, 2026

Summary

Makes FgaApiAuthenticationError inherit from FgaApiError so auth failures participate in shared API error handling.

Changes

  • Added regression test asserting FgaApiAuthenticationError instanceof FgaApiError
  • Updated class inheritance to extend FgaApiError
  • Kept auth-specific metadata (clientId, audience, grantType) and auth-specific message

Potential Breaking Change

  • FgaApiAuthenticationError is now also instanceof FgaApiError.
  • Consumer catch logic that checks FgaApiError before FgaApiAuthenticationError may now take a different branch than before.

Fixes #326

Copilot AI review requested due to automatic review settings February 16, 2026 18:52
@aaguiarz aaguiarz requested a review from a team as a code owner February 16, 2026 18:52
@dosubot
Copy link

dosubot bot commented Feb 16, 2026

Related Documentation

Checked 8 published document(s) in 1 knowledge base(s). No updates required.

How did I do? Any feedback?  Join Discord

@coderabbitai
Copy link

coderabbitai bot commented Feb 16, 2026

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Walkthrough

FgaApiAuthenticationError now extends FgaApiError instead of FgaError, enabling proper polymorphism for API error handling. Public properties are removed since they are inherited from the parent class. A test validates the instanceof relationship.

Changes

Cohort / File(s) Summary
Error Inheritance Structure
errors.ts
FgaApiAuthenticationError now extends FgaApiError; removed duplicate public properties (statusCode, statusText, method, requestURL, responseData, responseHeader, requestId); constructor simplified to delegate to super(err) with custom message handling via this.message.
Authentication Error Tests
tests/errors-authentication.test.ts
New test file validating that FgaApiAuthenticationError instances satisfy instanceof FgaApiError checks.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related issues

🚥 Pre-merge checks | ✅ 6
✅ Passed checks (6 passed)
Check name Status Explanation
Title check ✅ Passed The title 'fix: make FgaApiAuthenticationError inherit from FgaApiError' directly and clearly summarizes the main change—updating the inheritance of FgaApiAuthenticationError.
Linked Issues check ✅ Passed The pull request successfully meets all coding requirements from issue #326: FgaApiAuthenticationError now extends FgaApiError, a regression test validates the inheritance, and auth-specific fields and message behavior are preserved.
Out of Scope Changes check ✅ Passed All changes directly address the linked issue requirements. The inheritance change, property removals, and test addition are all within scope of fixing the error inheritance hierarchy.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Merge Conflict Detection ✅ Passed ✅ No merge conflicts detected when merging into main
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/issue-326-auth-error-inheritance

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov-commenter
Copy link

codecov-commenter commented Feb 16, 2026

Codecov Report

❌ Patch coverage is 66.66667% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 90.15%. Comparing base (a7090e2) to head (4099c22).

Files with missing lines Patch % Lines
errors.ts 66.66% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #327      +/-   ##
==========================================
+ Coverage   89.67%   90.15%   +0.47%     
==========================================
  Files          25       25              
  Lines        1492     1483       -9     
  Branches      279      255      -24     
==========================================
- Hits         1338     1337       -1     
+ Misses         94       88       -6     
+ Partials       60       58       -2     

☔ View full report in Codecov by Sentry.
📢 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.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes the inheritance hierarchy for FgaApiAuthenticationError to properly extend FgaApiError instead of FgaError, ensuring authentication failures participate in shared API error handling patterns.

Changes:

  • Updated FgaApiAuthenticationError to inherit from FgaApiError instead of FgaError
  • Removed duplicate property declarations that are now inherited from FgaApiError
  • Simplified constructor to call super(err) and set message afterward
  • Added regression test to verify FgaApiAuthenticationError instanceof FgaApiError

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
errors.ts Changed class inheritance and removed duplicate properties (statusCode, statusText, method, requestURL, responseData, responseHeader, requestId), simplified constructor
tests/errors-authentication.test.ts Added new test file with regression test asserting proper instanceof FgaApiError behavior

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
tests/errors-authentication.test.ts (1)

5-30: Consider adding assertions for inherited and auth-specific properties.

The instanceof check validates the fix for #326, but since the synthetic error already has all the fields, a few extra assertions would guard against future regressions in property propagation through the new inheritance chain.

💡 Suggested additional assertions
       const err = new FgaApiAuthenticationError(axiosError);
 
       expect(err).toBeInstanceOf(FgaApiError);
+      expect(err).toBeInstanceOf(Error);
+
+      // Inherited from FgaApiError
+      expect(err.statusCode).toBe(401);
+      expect(err.statusText).toBe("Unauthorized");
+      expect(err.requestURL).toBe("https://issuer.fga.example/oauth/token");
+
+      // Auth-specific properties
+      expect(err.clientId).toBe("client-id");
+      expect(err.audience).toBe("api-audience");
+      expect(err.grantType).toBe("client_credentials");
+      expect(err.apiErrorCode).toBe("auth_error");
+
+      // Custom message
+      expect(err.message).toBe("FGA Authentication Error. Unauthorized");

@aaguiarz
Copy link
Member Author

aaguiarz commented Feb 16, 2026

Addressed the review suggestion to strengthen the regression assertions.

Implemented in commit 4099c22:

  • added assertions for inherited fields (statusCode, statusText, requestURL)
  • added assertions for auth-specific fields (clientId, audience, grantType, apiErrorCode)
  • added assertions for base Error inheritance and authentication message text

tests/errors-authentication.test.ts passes locally with these checks.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

fix: FgaApiAuthenticationError should extend FgaApiError

2 participants