* Execute a GraphQL query against the LeetCode API
(query: string, variables: Record<string, any> = {})
| 26 | * Execute a GraphQL query against the LeetCode API |
| 27 | */ |
| 28 | private async executeQuery(query: string, variables: Record<string, any> = {}) { |
| 29 | try { |
| 30 | const response = await this.http.post(this.API_URL, { |
| 31 | query, |
| 32 | variables |
| 33 | }); |
| 34 | |
| 35 | if (response.data.errors) { |
| 36 | throw new Error(response.data.errors[0].message); |
| 37 | } |
| 38 | |
| 39 | return response.data.data; |
| 40 | } catch (error: unknown) { |
| 41 | if (error && typeof error === 'object' && 'response' in error && error.response) { |
| 42 | const axiosError = error as { response: { status: number, data?: any } }; |
| 43 | throw new Error(`API Error: ${axiosError.response.status} - ${axiosError.response.data?.message || JSON.stringify(axiosError.response.data)}`); |
| 44 | } else if (error && typeof error === 'object' && 'request' in error) { |
| 45 | throw new Error("Network Error: No response received from LeetCode API"); |
| 46 | } |
| 47 | // 如果是其他类型的错误,转换为Error类型 |
| 48 | if (error instanceof Error) { |
| 49 | throw error; |
| 50 | } |
| 51 | throw new Error(String(error)); |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Fetch user profile data |
no outgoing calls
no test coverage detected