<commit_before>class JsonWebToken
  def self.encode(payload, expiration = nil)
    expiration ||= Rails.application.secrets.jwt_expiration_hours

    payload = payload.dup
    payload['exp'] = expiration.to_i.hours.from_now.to_i

    JWT.encode(payload, Rails.application.secrets.jwt_secret)
  end

  def self.decode(token)
    decoded_token = JWT.decode(token, Rails.application.secrets.jwt_secret)

    decoded_token.first
  rescue => e
    Rails.logger.debug "Failed to decode token: '#{token}'"
    Rails.logger.debug e<commit_msg>Follows precedence for capturing and logging errors for jwt_secret<commit_after>class JsonWebToken
  def self.encode(payload, expiration = nil)
    expiration ||= Rails.application.secrets.jwt_expiration_hours

    payload = payload.dup
    payload['exp'] = expiration.to_i.hours.from_now.to_i

    JWT.encode(payload, Rails.application.secrets.jwt_secret)
  rescue => e
    Rails.logger.debug "Failed to encode JsonWebToken due to: #{e}"
    nil
  end

  def self.decode(token)
    decoded_token = JWT.decode(token, Rails.application.secrets.jwt_secret)

    decoded_token.first
  rescue => e
    Rails.logger.debug "Failed to decode token: '#{token}'"
    Rails.logger.debug e
{'fraction_non_alphanumeric': 0.10387469084913438, 'fraction_numerical': 0.0, 'mean_word_length': 4.079497907949791, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, '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': '2454661', 'n_tokens_mistral': 420, 'n_tokens_neox': 392, 'n_words': 80}