Skip to content

Add support for custom denied access reason#2

Open
jtinbergen wants to merge 1 commit into
9Morello:masterfrom
jtinbergen:feature/custom-errors
Open

Add support for custom denied access reason#2
jtinbergen wants to merge 1 commit into
9Morello:masterfrom
jtinbergen:feature/custom-errors

Conversation

@jtinbergen
Copy link
Copy Markdown

✨ Summary

This PR introduces custom deny reasons for buildAbacPolicy policies. It does so by wrapping the condition call in a try/catch and using the thrown error message into a DeniedAccessResult. It will fall back to the default message when no message property is present on the error.


🛠️ Changes

  • Added exception handling to the buildAbacPolicy function
  • Extended unit tests to cover custom denial reasons

🔍 Why

This change is part of providing better error reasons for failing policies so failure is easier to understand. Currently it only says the condition evaluated to false


⚠️ Notes for Reviewers

  • Please note that no existing test was changed and all existing and new test(s) are green.
  • An extra test was added to verify the try/catch error handing with custom reasons for buildAbacPolicy.

✅ Testing

  • ✅ All unit tests passing

@9Morello
Copy link
Copy Markdown
Owner

First of all, thanks for taking the time to make this PR, I appreciate it!
Could you elaborate a bit on your use case? Usually, you can indicate the reason for denying access by giving your policy a name. For example, if you have an ABAC policy called "Public documents have READ access for anyone accessing it", and that policy denies access, it should implicitly mean the document is not public.

Wrapping it in a try/catch blog may hide bugs on the underlying business logic as well.

@jtinbergen
Copy link
Copy Markdown
Author

jtinbergen commented Jun 13, 2025 via email

@9Morello
Copy link
Copy Markdown
Owner

@jtinbergen Sorry for not getting back to you sooner. I've just been busy at $dayjob and didn't have the time to put more thought on this PR. As to not block your use case, maybe you could consider vendoring the library, at least for the time being. If your toolchain supports TS directly, you only have to add a single file to your folder.

Again, sorry for the inconvenience.

@jtinbergen
Copy link
Copy Markdown
Author

jtinbergen commented Jul 9, 2025 via email

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