Hello developers. I hope you are all well. I have been writing some Ash Policies recently and things have been quite good. However as I was doing form submissions using AshPhoenix, I got this error while trying to perform a create action with a user that is not authorized to do so. Is there a way I can handle this error, probably catch it?
This is what i have done :
{:ok, region} ->
notify_parent({:saved, region})
socket =
socket
|> put_flash(:info, "Region #{socket.assigns.form.source.type}d successfully")
|> push_patch(to: socket.assigns.patch)
{:noreply, socket}
{:error, form} ->
dbg(form)
errors = form.source.source.errors
Ash.Error.Forbidden.Policy.report(errors)
{:noreply,
socket
|> put_flash(:error, "You are not authorized to perform this action")
|> push_patch(to: socket.assigns.patch)}
The outcome:
warning] Unhandled error in form submission for Marketingbsm.Outlet.Region.new
This error was unhandled because Ash.Error.Forbidden.Policy does not implement the `AshPhoenix.FormData.Error` protocol.
** (Ash.Error.Forbidden.Policy) Bread Crumbs:
> Error returned from: Marketingbsm.Outlet.Region.new
forbidden