You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
19 lines
468 B
TypeScript
19 lines
468 B
TypeScript
export function safeJsonParse<T>(data: any): T {
|
|
if (typeof data === 'string') {
|
|
try {
|
|
return JSON.parse(data);
|
|
} catch (error) {
|
|
console.error('Failed to parse JSON string:', error);
|
|
throw new Error('Invalid JSON response from server');
|
|
}
|
|
}
|
|
return data;
|
|
}
|
|
|
|
export function logApiResponse(endpoint: string, response: any) {
|
|
if (__DEV__) {
|
|
console.log(`[API Response - ${endpoint}]`, JSON.stringify(response, null, 2));
|
|
}
|
|
}
|
|
|