Sha256: 25ae7b7d62a721d56b9d5d287500f623e8b7f4253c103fedc92aa983310884e6

Contents?: true

Size: 915 Bytes

Versions: 3

Compression:

Stored size: 915 Bytes

Contents

# Formats a message string into application/problem+json format.

module PactBroker
  module Api
    module Decorators
      class CustomErrorProblemJSONDecorator

        # @option title [String]
        # @option type [String]
        # @option detail [String]
        # @option status [Integer] HTTP status code
        def initialize(title:, type:, detail:, status: )
          @title = title
          @type = type
          @detail = detail
          @status = status
        end

        # @return [Hash]
        def to_hash(user_options: {}, **__other)
          {
            "title" => @title,
            "type" => "#{user_options[:base_url]}/problem/#{@type}",
            "detail" => @detail,
            "status" => @status
          }
        end

        # @return [String] JSON
        def to_json(*args, **kwargs)
          to_hash(*args, **kwargs).to_json
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
pact_broker-2.107.1 lib/pact_broker/api/decorators/custom_error_problem_json_decorator.rb
pact_broker-2.107.0 lib/pact_broker/api/decorators/custom_error_problem_json_decorator.rb
pact_broker-2.107.0.beta.1 lib/pact_broker/api/decorators/custom_error_problem_json_decorator.rb