Sha256: 9e1a6dcafc4dff862ab376f2665265ff3ac5e9bdf70d3aefc2cc27601588b6d9

Contents?: true

Size: 1.19 KB

Versions: 16

Compression:

Stored size: 1.19 KB

Contents

# frozen_string_literal: true

module WCC::Contentful::App
  # Raised by {WCC::Contentful.validate_models!} if a content type in the space
  # does not match the validation defined on the associated model.
  class ValidationError < StandardError
    Message =
      Struct.new(:path, :error) do
        def to_s
          "#{path}: #{error}"
        end
      end

    attr_reader :errors

    def initialize(errors)
      @errors = ValidationError.join_msg_keys(errors)
      super("Content Type Schema from Contentful failed validation!\n  #{@errors.join("\n  ")}")
    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)
    end
  end

  class PageNotFoundError < StandardError
    attr_reader :slug

    def initialize(slug)
      super("Page not found: '#{slug}'")
      @slug = slug
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
wcc-contentful-app-1.2.0 lib/wcc/contentful/app/exceptions.rb
wcc-contentful-app-1.1.2 lib/wcc/contentful/app/exceptions.rb
wcc-contentful-app-1.1.1 lib/wcc/contentful/app/exceptions.rb
wcc-contentful-app-1.1.0 lib/wcc/contentful/app/exceptions.rb
wcc-contentful-app-1.0.8 lib/wcc/contentful/app/exceptions.rb
wcc-contentful-app-1.0.7 lib/wcc/contentful/app/exceptions.rb
wcc-contentful-app-1.0.6 lib/wcc/contentful/app/exceptions.rb
wcc-contentful-app-1.0.5 lib/wcc/contentful/app/exceptions.rb
wcc-contentful-app-1.0.4 lib/wcc/contentful/app/exceptions.rb
wcc-contentful-app-1.0.3 lib/wcc/contentful/app/exceptions.rb
wcc-contentful-app-1.0.2 lib/wcc/contentful/app/exceptions.rb
wcc-contentful-app-1.0.1 lib/wcc/contentful/app/exceptions.rb
wcc-contentful-app-1.0.0 lib/wcc/contentful/app/exceptions.rb
wcc-contentful-app-1.0.0.pre.rc3 lib/wcc/contentful/app/exceptions.rb
wcc-contentful-app-1.0.0.pre.rc2 lib/wcc/contentful/app/exceptions.rb
wcc-contentful-app-1.0.0.pre.rc1 lib/wcc/contentful/app/exceptions.rb