Skip to content

Commit

Permalink
(#27) CU-33zkt13 ensure safe string return from xml method
Browse files Browse the repository at this point in the history
* ensure safe string return from xml method

* version bump

* more warning conditions for RMA create failure
  • Loading branch information
NewAlexandria committed Aug 3, 2023
1 parent aa7d067 commit 2a12ea0
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
14 changes: 11 additions & 3 deletions lib/solidus_bactracs/api/request_runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def authenticated_call(serializer: nil, shipment: nil, method: :post, path: '/we
Rails.logger.info({ event: 'success CreateRMA', rma: shipment.number, response: parse_rma_creation_response(rma_response, "Message")})
shipment_synced(shipment)
return true
elsif rma_exists?(rma_response)
elsif rma_exists?(rma_response) or rma_fail?(rma_response)
return false
else
clear_cache
Expand Down Expand Up @@ -89,7 +89,7 @@ def authenticate!

raise RequestError.from_response(@response) unless @response # just try again for @retries?
if "false" == parse_authentication_response(@response, "Result")
Rails.logger.warn({ event: 'bactracs auth failed', error: parse_authentication_response(@response, "Message")})
Rails.logger.error({ event: 'bactracs auth failed', error: parse_authentication_response(@response, "Message")})
raise RequestError.from_response(@response)
end
sguid = parse_authentication_response(@response, "Message")
Expand All @@ -110,12 +110,20 @@ def create_rma_success?(response)
end

def rma_exists?(response)
if parse_rma_creation_response(response, "Message").match(/failed CreateRMA/)
Rails.logger.error({ event: 'bactracs failed CreateRMA', error: parse_rma_creation_response(response, "Message")})
return true
end
end

def rma_fail?(response)
if parse_rma_creation_response(response, "Message").match(/rma .* already exists/)
Rails.logger.warn({ event: 'bactracs failed CreateRMA', error: parse_rma_creation_response(response, "Message")})
Rails.logger.error({ event: 'bactracs failed CreateRMA', error: parse_rma_creation_response(response, "Message")})
return true
end
end


def shipment_synced(shipment)
shipment.update_attribute(:bactracs_synced_at, Time.zone.now)

Expand Down
5 changes: 3 additions & 2 deletions lib/solidus_bactracs/api/shipment_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@ def call(sguid: nil)
end
end
end
Rails.logger.info(xml.to_s)
xml
# Rails.logger.info(xml.to_s)
@xml = xml.to_xml.sub(/<to_xml\/>$/,'')
return @xml
end

def line_items_xml(xml: nil, line_item: nil, variant: nil, order: nil)
Expand Down
2 changes: 1 addition & 1 deletion lib/solidus_bactracs/console_harness.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def try_one(a_shipment = nil)
# resp = @runner.call(:post, '/orders/createorders', [serialize(shipment)])
resp = @runner.authenticated_call(shipment: shipment, serializer: @syncer.client.shipment_serializer)
if resp
@cursor += 1
@cursor += 1 if (a_shipment == @shipments[@cursor] || shipment == @shipments[@cursor])
return resp
end
ensure
Expand Down
2 changes: 1 addition & 1 deletion lib/solidus_bactracs/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module SolidusBactracs
VERSION = '3.5.1'
VERSION = '3.5.2'
end

0 comments on commit 2a12ea0

Please sign in to comment.