Sha256: f1adb4a430e59c7586202b756bd657d7235c410dceba2aafb39acc9bf77dfc0a

Contents?: true

Size: 786 Bytes

Versions: 1

Compression:

Stored size: 786 Bytes

Contents

# frozen_string_literal: true

module OpenaiAsissistant
  # A error response of openai
  class ErrorResponse
    # @return [String] error message
    attr_accessor :message
    # @return [String] type of error
    attr_accessor :type
    # @return [String] parameter that caused the error
    attr_accessor :param
    # @return [String] error code of openai
    attr_accessor :code

    def initialize(**args)
      args.each do |k, v|
        instance_variable_set("@#{k}", v) unless v.nil?
      end
    end

    def self.from_json(response_body)
      data = JSON.parse(response_body)["error"]
      OpenaiAsissistant::ErrorResponse.new(
        message: data["message"],
        type: data["type"],
        param: data["param"],
        code: data["code"]
      )
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
openai-assistant-1.0.0 lib/openai_assistant/error_response.rb