<commit_before>import * as Sentry from "@sentry/browser"

export class NetworkError extends Error {
  response: any
}

export class ErrorWithMetadata extends Error {
  metadata: object
  decoratedMessage: string
  constructor(message, metadata = {}) {
    super(message)
    this.decoratedMessage = message + " | " + JSON.stringify(metadata)
    this.metadata = metadata
    if (Error.captureStackTrace) {
      Error.captureStackTrace(this, this.constructor)
    }
  }
}

export const sendErrorToService = (error: Error | ErrorWithMetadata) => {
  Sentry.withScope(scope => {
    if (error instanceof ErrorWithMetadata) {
      Object.keys(error.metadata).forEach(key => {
        scope.setExtra(key, error.metadata[key])
      })
    }
    Sentry.captureException(error)
  })
}<commit_msg>Abstract out callback in sendErrorToService into its own method; remove decoratedMessage from ErrorWithMetadata since there's no current use<commit_after>import * as Sentry from "@sentry/browser"

export class NetworkError extends Error {
  response: any
}

export class ErrorWithMetadata extends Error {
  metadata: object
  decoratedMessage: string
  constructor(message, metadata = {}) {
    super(message)
    this.metadata = metadata
    if (Error.captureStackTrace) {
      Error.captureStackTrace(this, this.constructor)
    }
  }
}

export const reportError = error => scope => {
  if (error instanceof ErrorWithMetadata) {
    Object.keys(error.metadata).forEach(key => {
      scope.setExtra(key, error.metadata[key])
    })
  }
  Sentry.captureException(error)
}

export const sendErrorToService = (error: Error | ErrorWithMetadata) => {
  Sentry.withScope(reportError(error))
}
{'fraction_non_alphanumeric': 0.10297619047619047, 'fraction_numerical': 0.0, 'mean_word_length': 4.078549848942598, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 10, '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': '5133208', 'n_tokens_mistral': 468, 'n_tokens_neox': 469, 'n_words': 115}