export const logoutIfUnauthorized = async (response: Response) => {
  /* отключили из-за доступа без авторизации */
  if (response.status === 401 || response.status === 403) {
    window.dispatchEvent(new Event('FORBIDDEN_REQUEST'))
  }

  const error = new Error(response.statusText)
  // eslint-disable-next-line no-console
  console.error(error)

  const body = await response.json()
  return Promise.reject(body)
}
