<commit_before>module Spree
  module Wombat
    module Handler
      class AddShipmentHandler < Base

        def process

          shipment = @payload[:shipment]

          order_number = shipment.delete(:order_id)
          order = Spree::Order.find_by_number(order_number)
          return response("Can't find order #{order_number} associated with this shipment", 500) unless order

          shipment[:order_id] = order.id

          external_id = shipment.delete(:id)
<commit_msg>raise error when trying to add an already existing shipment<commit_after>module Spree
  module Wombat
    module Handler
      class AddShipmentHandler < Base

        def process

          shipment = @payload[:shipment]

          order_number = shipment.delete(:order_id)
          order = Spree::Order.find_by_number(order_number)
          return response("Can't find order #{order_number} associated with this shipment", 500) unless order

          shipment[:order_id] = order.id

          external_id = shipment.delete(:id)

          existing_shipment = Spree::Shipment.find_by_number(external_id)
          return response("Already have a shipment for order #{order_number} associated with shipment number #{external_id}", 500) if existing_shipment


{'fraction_non_alphanumeric': 0.07612179487179487, 'fraction_numerical': 0.007211538461538462, 'mean_word_length': 3.0551948051948052, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6030860', 'n_tokens_mistral': 354, 'n_tokens_neox': 321, 'n_words': 93}