Module: NetsuiteApi::Concerns::ResponseHandler
Defined Under Namespace
Classes: NetSuiteApiError
Instance Method Summary
collapse
Instance Method Details
#delete_response_handler(response) ⇒ Object
36
37
38
39
40
41
42
|
# File 'lib/netsuite_api/concerns/response_handler.rb', line 36
def delete_response_handler(response)
if response.success?
true
else
error_handler(response)
end
end
|
#error_handler(response) ⇒ Object
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/netsuite_api/concerns/response_handler.rb', line 44
def error_handler(response)
begin
response_body = JSON.parse(response.body)
title = response_body["title"] || "NetSuite API Error"
details = response_body["o:errorDetails"] || "No additional details provided."
rescue JSON::ParserError
title = "Invalid API Response"
details = response.body.to_s.strip.empty? ? "Empty response body" : response.body
end
NetsuiteApi.logger.error("NetSuite API Error: #{title} - #{details}")
raise NetSuiteApiError.new(title, details)
end
|
#get_response_handler(response) ⇒ Object
14
15
16
17
18
19
20
|
# File 'lib/netsuite_api/concerns/response_handler.rb', line 14
def get_response_handler(response)
if response.success?
JSON.parse(response.body)
else
error_handler(response)
end
end
|
#post_and_patch_response_handler(response) ⇒ Object
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/netsuite_api/concerns/response_handler.rb', line 22
def post_and_patch_response_handler(response)
if response.success?
location = response.["location"]
if location
location.split('/').last
else
NetsuiteApi.logger.error("NetSuite API Error: No location header in response")
nil
end
else
error_handler(response)
end
end
|