Closed alextakitani closed 4 years ago
You can put your errors into context.
Indeed but that way I have to log the errors on my controller, right?
Not really, you can do it from an interactor.
def call
ActiveRecord::Base.transaction do
create_resource
end
rescue StandardError => e
Rails.logger.info "Failed to create resource #{e.message}"
context.fail!(message: 'Could not create your resource')
end
Another example:
def call
log_and_fail unless resource.update(params)
end
private
def log_and_fail
Rails.logger.info "Failed to update resource #{resource.errors.full_messages}"
context.fail!(message: 'Fail to update resource resource')
end
Is pretty much your call.
if you have an organizer for example I would suggest to log inside the interactors it make sense to log. There is no right and wrong for it. But on my code I avoid log errors on the controller level.
Thanks!
I want to log when my Interactor fails, is there a way to do it from inside of the class?
Thanks!