···253254 // Try to read the response body for detailed error information
255 let errorMessage = `Request failed: ${response.status} ${response.statusText}`;
256- let errorDetails = "";
257258 try {
259 const errorBody = await response.json();
260 if (errorBody?.message) {
261 errorMessage += ` - ${errorBody.message}`;
262- errorDetails = errorBody.message;
263 } else if (errorBody?.error) {
264 errorMessage += ` - ${errorBody.error}`;
265- errorDetails = errorBody.error;
266 }
267268- // Log detailed error information for debugging
269- if (response.status === 401) {
270- console.error(`🔍 Authentication Debug Info:`);
271- console.error(` URL: ${url}`);
272- console.error(` Method: ${httpMethod}`);
273- console.error(` Auth Header: ${(requestInit.headers as any)?.Authorization ? 'Present' : 'Missing'}`);
274- if ((requestInit.headers as any)?.Authorization) {
275- const authHeader = (requestInit.headers as any).Authorization;
276- console.error(` Auth Type: ${authHeader.split(' ')[0]}`);
277- console.error(` Token Length: ${authHeader.split(' ')[1]?.length || 0} chars`);
278- }
279- console.error(` Error Details: ${errorDetails}`);
280- console.error(` Full Response Body:`, errorBody);
281- }
282 } catch {
283 // If we can't parse the response body, just use the status message
284- if (response.status === 401) {
285- console.error(`🔍 Authentication Debug Info:`);
286- console.error(` URL: ${url}`);
287- console.error(` Method: ${httpMethod}`);
288- console.error(` Auth Header: ${(requestInit.headers as any)?.Authorization ? 'Present' : 'Missing'}`);
289- console.error(` Could not parse error response body`);
290- }
291 }
292293 throw new Error(errorMessage);
···253254 // Try to read the response body for detailed error information
255 let errorMessage = `Request failed: ${response.status} ${response.statusText}`;
0256257 try {
258 const errorBody = await response.json();
259 if (errorBody?.message) {
260 errorMessage += ` - ${errorBody.message}`;
0261 } else if (errorBody?.error) {
262 errorMessage += ` - ${errorBody.error}`;
0263 }
26400000000000000265 } catch {
266 // If we can't parse the response body, just use the status message
0000000267 }
268269 throw new Error(errorMessage);