<commit_before>import axios from 'axios'

import { httpCodes } from 'server/utils/constants'
import { messageTerminal } from 'server/utils/general'

import { findStorageData, isDevelopment } from 'client/utils'
import { JWT_NAME, APP_URL } from 'client/constants'

const http = axios.create({ baseURL: APP_URL })

http.interceptors.request.use((config) => {
  const token = findStorageData(JWT_NAME)
  token && (config.headers.Authorization = `Bearer ${token}`)

  return {
    ...config,
    withCredentials: true,
    validateStatus: status =>
      Object.values(httpCodes).some(({ id }) => id === status)
  }
})

http.interceptors.response.use(
  response => {
    if (response?.data && response?.status < httpCodes.badRequest.id) {
      return typeof response === 'string'
        ? response.data.json()
        : response.data
    }

    if (response.status === httpCodes.unauthorized.id) {
      const configErrorParser = {
        color: 'red',
        error: response?.data?.message ?? response?.statusText,
        message: 'Error request: %s'
      }

      isDevelopment() && messageTerminal(configErrorParser)
    }

    return Promise.reject(response)
  },
  error => {
    console.log('error interceptor', error)
    return error
  }
)
<commit_msg>F OpenNebula/one#5422: Add request timeout<commit_after>import axios from 'axios'

import { httpCodes } from 'server/utils/constants'
import { messageTerminal } from 'server/utils/general'

import { findStorageData, isDevelopment } from 'client/utils'
import { T, JWT_NAME, APP_URL } from 'client/constants'

const http = axios.create({ baseURL: APP_URL })

http.interceptors.request.use(config => {
  const token = findStorageData(JWT_NAME)
  token && (config.headers.Authorization = `Bearer ${token}`)

  return {
    ...config,
    timeout: 45_000,
    timeoutErrorMessage: T.Timeout,
    withCredentials: true,
    validateStatus: status =>
      Object.values(httpCodes).some(({ id }) => id === status)
  }
})

http.interceptors.response.use(
  response => {
    if (response?.data && response?.status < httpCodes.badRequest.id) {
      return typeof response === 'string'
        ? response.data.json()
        : response.data
    }

    if (response.status === httpCodes.unauthorized.id) {
      const configErrorParser = {
        color: 'red',
        error: response?.data?.message ?? response?.statusText,
        message: 'Error request: %s'
      }

      isDevelopment() && messageTerminal(configErrorParser)
    }

    return Promise.reject(response)
  },
  error => error
)

{'fraction_non_alphanumeric': 0.13586530931871574, 'fraction_numerical': 0.003523884103367267, 'mean_word_length': 3.3086003372681283, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5092427', 'n_tokens_mistral': 796, 'n_tokens_neox': 775, 'n_words': 167}