Skip to content

Commit

Permalink
raise CouchbaseOrm::Error::RecordInvalid
Browse files Browse the repository at this point in the history
(cherry picked from commit 13d3bee)
  • Loading branch information
Giallombardo Nathan authored and Giallombardo Nathan committed May 30, 2024
1 parent d23e67b commit 132bcf2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
6 changes: 6 additions & 0 deletions lib/couchbase-orm/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -339,5 +339,11 @@ def eql?(other)
def ==(other)
super || other.instance_of?(self.class) && !id.nil? && other.id == id
end

private

def raise_validation_error
raise CouchbaseOrm::Error::RecordInvalid.new(self)
end
end
end
16 changes: 8 additions & 8 deletions lib/couchbase-orm/error.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@ def initialize(message = nil, record = nil)
end

class RecordInvalid < Error
def initialize(message = nil, record = nil)
def initialize(record = nil)
if record
errors = record.errors.full_messages.join(", ")
message = I18n.t(
:"couchbase.#{record.class.design_document}.errors.messages.record_invalid",
errors: errors,
default: :"couchbase.errors.messages.record_invalid"
)
@record = record
errors = @record.errors.full_messages.join(", ")
message = I18n.t(:"#{@record.class.i18n_scope}.errors.messages.record_invalid", errors: errors, default: :"errors.messages.record_invalid")
else
message = "Record invalid"
end
super(message, record)
end
end
class TypeMismatchError < Error; end
class RecordExists < Error; end
class CouchbaseOrm::Error::EmptyNotAllowed < Error; end
class EmptyNotAllowed < Error; end
class DocumentNotFound < Error; end
end
end

0 comments on commit 132bcf2

Please sign in to comment.