Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom error #13

Open
arturictus opened this issue Jan 15, 2018 · 0 comments
Open

Custom error #13

arturictus opened this issue Jan 15, 2018 · 0 comments

Comments

@arturictus
Copy link
Owner

arturictus commented Jan 15, 2018

Add custom errors for rescuing from them and callback to rescue from them

class MySerializer < EasySerializer::Base
  rescue_from :all, do: ->(e) { "log error" }, default: nil
  rescue_from EasySerializer::NoMethodError, do: ->(e) { "log error" }, default: nil

  attribute :name, rescue_from: {errors: :all, do: ->(e) { "log error" }, reraise: true }

  attribute :lastname do
    rescue_from(EasySerializer::NoMethodError,
                do: ->(e) { "log error" },
                default: nil) do
      raise 'thing'
    end
  end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant