Errors
Error Structure
{
email: ["must be a valid email"],
password: ["is too short", "must contain at least one number"]
}Adding Errors
class ParsePage < ApplicationService
# Arguments
arg :url, type: String
# ...
# Steps
step :validate
step :parse
# ...
private
def validate
# Multiple errors can be added with the same key
errors.add(:url, "must be a valid URL") unless url.match?(URI::DEFAULT_PARSER.make_regexp)
errors.add(:url, "must be a secure link") unless url.start_with?("https")
end
# ...
endQuick Error with fail!
fail!Reading Errors
Adding Warnings
Copying Errors
From ActiveRecord Models
From Another Service
Converting Errors to Hash
Per-Message Options
Control Break Behavior
Control Rollback Behavior
Checking for Errors and Warnings
Exception Classes
Exception
Description
MissingTypeError
NoStepsError
What's next?
Last updated