38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/intelligence/adapters/samba_nova.rb', line 38
def chat_result_error_attributes( response )
error_type, error_description = to_error_response( response.status )
result = {
error_type: error_type.to_s,
error_description: error_description
}
parsed_body = JSON.parse( response.body, symbolize_names: true ) rescue nil
if parsed_body &&
parsed_body.respond_to?( :include? ) && parsed_body.include?( :error ) &&
parsed_body[ :error ].is_a?( String )
result[ :error_description ] = parsed_body[ :error ]
elsif response.[ 'content-type' ].start_with?( 'text/plain' ) &&
response.body && response.body.length > 0
result[ :error_description ] = response.body
end
result
end
|