lib/wcc/contentful/exceptions.rb in wcc-contentful-0.2.2 vs lib/wcc/contentful/exceptions.rb in wcc-contentful-0.3.0.pre.rc
- old
+ new
@@ -1,40 +1,37 @@
# frozen_string_literal: true
module WCC::Contentful
- class ValidationError < StandardError
- Message =
- Struct.new(:path, :error) do
- def to_s
- "#{path}: #{error}"
- end
- end
+ class SyncError < StandardError
+ end
- attr_reader :errors
+ # Raised when a constant under {WCC::Contentful::Model} does not match to a
+ # content type in the configured Contentful space
+ class ContentTypeNotFoundError < NameError
+ end
- def initialize(errors)
- @errors = ValidationError.join_msg_keys(errors)
- super("Content Type Schema from Contentful failed validation!\n #{@errors.join("\n ")}")
+ # Raised when an entry contains a circular reference and cannot be represented
+ # as a flat tree.
+ class CircularReferenceError < StandardError
+ attr_reader :stack
+ attr_reader :id
+
+ def initialize(stack, id)
+ @id = id
+ @stack = stack.slice(stack.index(id)..stack.length)
+ super('Circular reference detected!')
end
- # Turns the error messages hash into an array of message structs like:
- # menu.fields.name.type: must be equal to String
- def self.join_msg_keys(hash)
- ret =
- hash.map do |k, v|
- if v.is_a?(Hash)
- msgs = join_msg_keys(v)
- msgs.map { |msg| Message.new(k.to_s + '.' + msg.path, msg.error) }
- else
- v.map { |msg| Message.new(k.to_s, msg) }
- end
- end
- ret.flatten(1)
+ def message
+ return super unless stack
+
+ super + "\n " \
+ "#{stack.last} points to #{id} which is also it's ancestor\n " +
+ stack.join('->')
end
end
- class SyncError < StandardError
- end
-
- class ContentTypeNotFoundError < NameError
+ # Raised by {WCC::Contentful::ModelMethods#resolve Model#resolve} when attempting
+ # to resolve an entry's links and that entry cannot be found in the space.
+ class ResolveError < StandardError
end
end