Exception: BetterService::Errors::Configuration::NilUserError

Inherits:
ConfigurationError show all
Defined in:
lib/better_service/errors/configuration/nil_user_error.rb

Overview

Raised when a service is initialized with nil user when user is required

By default, all BetterService services require a user object. This error is raised during initialization if user is nil and allow_nil_user is not configured.

Examples:

Service called with nil user (will raise error)

class MyService < BetterService::Services::Base
  schema do
    required(:name).filled(:string)
  end
end

MyService.new(nil, params: { name: "test" })
# => raises NilUserError

Allowing nil user

class MyService < BetterService::Services::Base
  config do
    allow_nil_user true
  end

  schema do
    required(:name).filled(:string)
  end
end

MyService.new(nil, params: { name: "test" })  # OK

Instance Attribute Summary

Attributes inherited from BetterServiceError

#code, #context, #original_error, #timestamp

Method Summary

Methods inherited from BetterServiceError

#backtrace, #detailed_message, #initialize, #inspect, #to_h

Constructor Details

This class inherits a constructor from BetterService::BetterServiceError