<commit_before>import Axios from 'axios'
import i18n from '@/i18n'
import { Notify, debounce } from 'quasar'

import { camelizeKeys, underscorizeKeys } from '@/services/utils'
import { isValidationError } from '@/store/helpers'

/*
* Axios configured for Django REST API
*/

const axios = Axios.create({
  xsrfCookieName: 'csrftoken',
  xsrfHeaderName: 'X-CSRFTOKEN',
})

const showDebouncedWarning = debounce((message) => {
  Notify.create({
    type: 'warning',
    position: 'bottom-left',
    timeout: 5000,
    message,
  })
}, 5000, true)

axios.interceptors.request.use(request => {
  if (request.data instanceof FormData) {
    return request
  }
  request.data = underscorizeKeys(request.data)
  return request
}, error => {
  showDebouncedWarning(i18n.t('GLOBAL.CONNECTION_INTERRUPTED'))
  return Promise.reject(error)
})

axios.interceptors.response.use(response => {
  response.data = camelizeKeys(response.data)
  return response
}, async error => {
  if (error.response && error.response.data) {
    error.response.data = camelizeKeys(error.response.data)
  }
  if (!isValidationError(error)) {
    showDebouncedWarning(i18n.t('GLOBAL.SERVER_ERROR'))
  }
  throw error
})

export default axios

export function parseCursor (c) {
  return c ? c.substr(c.indexOf('/api')) : null
}<commit_msg>use throttle instead of debounce for warning<commit_after>import Axios from 'axios'
import i18n from '@/i18n'
import { Notify, throttle } from 'quasar'

import { camelizeKeys, underscorizeKeys } from '@/services/utils'
import { isValidationError } from '@/store/helpers'

/*
* Axios configured for Django REST API
*/

const axios = Axios.create({
  xsrfCookieName: 'csrftoken',
  xsrfHeaderName: 'X-CSRFTOKEN',
})

const makeThrottledWarner = (message) =>
  throttle(() =>
    Notify.create({
      type: 'warning',
      position: 'bottom-left',
      timeout: 5000,
      message: i18n.t(message),
    }),
  5000)

const showConnectionInterruptedWarning = makeThrottledWarner('GLOBAL.CONNECTION_INTERRUPTED')
const showServerError = makeThrottledWarner('GLOBAL.SERVER_ERROR')

axios.interceptors.request.use(request => {
  if (request.data instanceof FormData) {
    return request
  }
  request.data = underscorizeKeys(request.data)
  return request
}, error => {
  showConnectionInterruptedWarning()
  return Promise.reject(error)
})

axios.interceptors.response.use(response => {
  response.data = camelizeKeys(response.data)
  return response
}, async error => {
  if (error.response && error.response.data) {
    error.response.data = camelizeKeys(error.response.data)
  }
  if (!isValidationError(error)) {
    showServerError()
  }
  throw error
})

export default axios

export function parseCursor (c) {
  return c ? c.substr(c.indexOf('/api')) : null
}
{'fraction_non_alphanumeric': 0.12969653179190752, 'fraction_numerical': 0.01083815028901734, 'mean_word_length': 4.39766081871345, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 14, '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': '2059806', 'n_tokens_mistral': 943, 'n_tokens_neox': 909, 'n_words': 195}