arc icon indicating copy to clipboard operation
arc copied to clipboard

Custom error keys returned from validate function

Open cichaczem opened this issue 9 years ago • 0 comments

Hi Sean, I have a specific case: I'd like to user arc and arc_ecto to validate if extension and MIME type of uploaded file are allowed in the current schema and show the reason of invalidity to the user. I changes validate function. Now it enforces Tuple as the return type {:ok, :valid} or {:error, :reason}.

Unfortunately, it won't work for me because of Ecto cast function which return type is either a Tuple {:ok, casted_valie} or an Atom :error.

I'm creating pull request because the code works and some people may find it useful. Feel free to either accept or reject it.

For now only and probably the best way of solving my problem is to run the validations twice. Once in validate function and once after parameters have been cast to their corresponding Ecto types.

I'll gladly accept any advice regarding this case.

Best, Dawid

cichaczem avatar May 10 '16 13:05 cichaczem