Skip to content

Instantly share code, notes, and snippets.

@KamilLelonek
Last active August 29, 2015 14:10
Show Gist options
  • Save KamilLelonek/1ba97620ced153d05b6e to your computer and use it in GitHub Desktop.
Save KamilLelonek/1ba97620ced153d05b6e to your computer and use it in GitHub Desktop.
Exception driven development
class ClientsController < ActionController::API
def update_registration_number
update_registration_number_service.(registration_number)
render_success
rescue UpdateRegistrationNumber::RegistrationNumberAlreadyExist
render_error
end
# ...
end
class UpdateRegistrationNumber
RegistrationNumberAlreadyExist = Class.new(StandardError)
def call(registration_number)
raise RegistrationNumberAlreadyExist if exist?(registration_number)
# ...
end
# ...
end
@rafaelgonzalez
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment