(
endpoint: string,
options: RequestOptions = {}
)
| 102 | } |
| 103 | |
| 104 | async request<T>( |
| 105 | endpoint: string, |
| 106 | options: RequestOptions = {} |
| 107 | ): Promise<T> { |
| 108 | const { skipAuth = false, headers = {}, ...restOptions } = options; |
| 109 | |
| 110 | const authHeaders = skipAuth ? {} : await this.getAuthHeaders(); |
| 111 | |
| 112 | const finalHeaders = { |
| 113 | 'Content-Type': 'application/json', |
| 114 | ...authHeaders, |
| 115 | ...headers, |
| 116 | }; |
| 117 | |
| 118 | const url = `${this.baseURL}${endpoint}`; |
| 119 | const method = restOptions.method || 'GET'; |
| 120 | |
| 121 | // Log API call in development |
| 122 | logApiCall(method, url, restOptions.body ? JSON.parse(restOptions.body as string) : undefined); |
| 123 | |
| 124 | try { |
| 125 | const response = await fetch(url, { |
| 126 | ...restOptions, |
| 127 | headers: finalHeaders, |
| 128 | credentials: 'include', // Important: Include cookies in requests |
| 129 | }); |
| 130 | |
| 131 | const result = await this.handleResponse<T>(response, { endpoint, options }); |
| 132 | logApiResponse(url, result); |
| 133 | return result; |
| 134 | } catch (error) { |
| 135 | logApiResponse(url, null, error); |
| 136 | throw error; |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | async get<T>(endpoint: string, options?: RequestOptions): Promise<T> { |
| 141 | return this.request<T>(endpoint, { ...options, method: 'GET' }); |
no test coverage detected