Class: Vellum::VellumError

Inherits:
Object
  • Object
show all
Defined in:
lib/vellum_ai/types/vellum_error.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message:, code:, additional_properties: nil) ⇒ VellumError

Parameters:

  • message (String)
  • code (VELLUM_ERROR_CODE_ENUM)
  • additional_properties (OpenStruct) (defaults to: nil)

    Additional properties unmapped to the current class definition



14
15
16
17
18
19
20
21
# File 'lib/vellum_ai/types/vellum_error.rb', line 14

def initialize(message:, code:, additional_properties: nil)
  # @type [String]
  @message = message
  # @type [VELLUM_ERROR_CODE_ENUM]
  @code = code
  # @type [OpenStruct] Additional properties unmapped to the current class definition
  @additional_properties = additional_properties
end

Instance Attribute Details

#additional_propertiesObject (readonly)

Returns the value of attribute additional_properties.



8
9
10
# File 'lib/vellum_ai/types/vellum_error.rb', line 8

def additional_properties
  @additional_properties
end

#codeObject (readonly)

Returns the value of attribute code.



8
9
10
# File 'lib/vellum_ai/types/vellum_error.rb', line 8

def code
  @code
end

#messageObject (readonly)

Returns the value of attribute message.



8
9
10
# File 'lib/vellum_ai/types/vellum_error.rb', line 8

def message
  @message
end

Class Method Details

.from_json(json_object:) ⇒ VellumError

Deserialize a JSON object to an instance of VellumError

Parameters:

  • json_object (JSON)

Returns:



27
28
29
30
31
32
33
# File 'lib/vellum_ai/types/vellum_error.rb', line 27

def self.from_json(json_object:)
  struct = JSON.parse(json_object, object_class: OpenStruct)
  parsed_json = JSON.parse(json_object)
  message = struct.message
  code = VELLUM_ERROR_CODE_ENUM.key(parsed_json["code"]) || parsed_json["code"]
  new(message: message, code: code, additional_properties: struct)
end

.validate_raw(obj:) ⇒ Void

Leveraged for Union-type generation, validate_raw attempts to parse the given hash and check each fields type against the current object’s property definitions.

Parameters:

  • obj (Object)

Returns:

  • (Void)


46
47
48
49
# File 'lib/vellum_ai/types/vellum_error.rb', line 46

def self.validate_raw(obj:)
  obj.message.is_a?(String) != false || raise("Passed value for field obj.message is not the expected type, validation failed.")
  obj.code.is_a?(VELLUM_ERROR_CODE_ENUM) != false || raise("Passed value for field obj.code is not the expected type, validation failed.")
end

Instance Method Details

#to_json(*_args) ⇒ JSON

Serialize an instance of VellumError to a JSON object

Returns:

  • (JSON)


38
39
40
# File 'lib/vellum_ai/types/vellum_error.rb', line 38

def to_json(*_args)
  { "message": @message, "code": VELLUM_ERROR_CODE_ENUM[@code] || @code }.to_json
end