subvisual/dictator

Add a handler for resources not found

frm opened this issue · 2 comments

frm commented

If a resource is not found, we're currently calling the policy with nil for the resource value. This means that a lot of times, the policies will have a function branch pattern matching on nil and calling a FallbackController or specific handler.

We should add that as an alternative, similar to the current unauthorised handler.

Since both the new handler and the unauthorised one are plugs, we should also update the README with an example using a MyAppWeb.FallbackController as the handler

Agree, but I don't think we should care about a fallback controller at all.
If people want to reach a fallback controller, the way to do that is to return an error tuple. So we can allow the option of doing that when the resource is nil, but I'd say it's up to the user to catch that on the fallback controller

frm commented

The fallback controller was just an example for the README. A custom unauthorized handler that would defer errors to the fallback controller, to keep all the error handling logic in the same module (I've found myself doing this).