File size: 1,207 Bytes
21cac8a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import axios from 'axios'

const api = axios.create({
  baseURL: '/api',
  timeout: 30000,
})

// Add request interceptor for error handling
api.interceptors.response.use(
  (response) => response,
  (error) => {
    console.error('API Error:', error)

    if (error.response?.data?.error) {
      throw new Error(error.response.data.error)
    }

    if (error.code === 'ECONNABORTED') {
      throw new Error('Request timeout - please try again')
    }

    throw new Error(error.message || 'Network error occurred')
  }
)

export const startAnalysis = async ({ url, options }) => {
  const response = await api.post('/analyze', {
    url,
    options
  })
  return response.data
}

export const getAnalysisResult = async (analysisId) => {
  const response = await api.get(`/analyze/${analysisId}`)
  return response.data
}

export const getAnalysisReport = async (analysisId) => {
  const response = await api.get(`/analyze/${analysisId}/report`)
  return response.data
}

export const getHealthStatus = async () => {
  const response = await api.get('/health')
  return response.data
}

export const getActiveAnalyses = async () => {
  const response = await api.get('/analyze')
  return response.data
}