I’m creating service objects to handle business logic that does not belong in ActiveRecord models neither should it be in the controllers. I am seeking opinions on how to bubble back errors from a service object back to the controller calling it without using any gems. For example, this would be in my controller:
class SessionsController < ApplicationController def create result = AuthenticateUser.call(session_params) if result.success? session[:user_token] = result.token redirect_to root_path else flash.now[:message] = t(result.error) render :new end end end
For the sake of brevity, I have left out the private method that constructs the
I would like the service object (
AuthenticateUser) to be able to return an error message and also to check if it successful or not. I appreciate suggestions on how to construct a module to handle errors which can bubble back up to the caller of the object.