mirror of
https://github.com/i701/sarlink-portal.git
synced 2025-07-15 11:05:50 +00:00
fix: enhance error handling in handleApiResponse function for better clarity 🐛
This commit is contained in:
@ -11,7 +11,7 @@ export async function handleApiResponse<T>(
|
||||
response: Response,
|
||||
fnName?: string,
|
||||
) {
|
||||
const responseData = await response.json();
|
||||
const responseData = await response.json()
|
||||
if (response.status === 401) {
|
||||
console.log('response data', responseData)
|
||||
throw new Error("UNAUTHORIZED");
|
||||
@ -32,7 +32,7 @@ export async function handleApiResponse<T>(
|
||||
|
||||
if (!response.ok) {
|
||||
console.log(`API Error Response from ${fnName}:`, responseData);
|
||||
throw new Error(responseData.message || "Something went wrong.");
|
||||
throw new Error(responseData.message || responseData.detail || "Something went wrong.");
|
||||
}
|
||||
|
||||
return responseData as T;
|
||||
|
Reference in New Issue
Block a user