update
This commit is contained in:
@@ -151,7 +151,6 @@ export const getTicketCategories = async (): Promise<TicketCategory[]> => {
|
||||
// Handle paginated response
|
||||
return data.results || data;
|
||||
} catch (error) {
|
||||
console.error('Error fetching ticket categories:', error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
@@ -167,7 +166,6 @@ export const getTicketStatuses = async (): Promise<TicketStatus[]> => {
|
||||
// Handle paginated response
|
||||
return data.results || data;
|
||||
} catch (error) {
|
||||
console.error('Error fetching ticket statuses:', error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
@@ -183,7 +181,6 @@ export const getTicketPriorities = async (): Promise<TicketPriority[]> => {
|
||||
// Handle paginated response
|
||||
return data.results || data;
|
||||
} catch (error) {
|
||||
console.error('Error fetching ticket priorities:', error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
@@ -204,17 +201,38 @@ export const createTicket = async (data: CreateTicketData): Promise<SupportTicke
|
||||
if (!response.ok) {
|
||||
const errorData = await response.json().catch(() => ({}));
|
||||
|
||||
// Handle validation errors
|
||||
if (response.status === 400 && errorData.user_email) {
|
||||
throw new Error(errorData.user_email[0] || 'Email validation failed');
|
||||
// Handle specific HTTP status codes
|
||||
if (response.status === 400) {
|
||||
// Handle validation errors
|
||||
if (errorData.user_email) {
|
||||
throw new Error(errorData.user_email[0] || 'Email validation failed');
|
||||
}
|
||||
if (errorData.title) {
|
||||
throw new Error(errorData.title[0] || 'Title is required');
|
||||
}
|
||||
if (errorData.description) {
|
||||
throw new Error(errorData.description[0] || 'Description is required');
|
||||
}
|
||||
if (errorData.user_name) {
|
||||
throw new Error(errorData.user_name[0] || 'Name is required');
|
||||
}
|
||||
// Generic validation error
|
||||
throw new Error(errorData.detail || errorData.message || 'Please check all required fields and try again');
|
||||
} else if (response.status === 429) {
|
||||
throw new Error('Too many requests. Please wait a moment and try again');
|
||||
} else if (response.status >= 500) {
|
||||
throw new Error('Server error. Please try again later');
|
||||
} else if (response.status === 403) {
|
||||
throw new Error('Access denied. Please contact support if this persists');
|
||||
} else if (response.status === 404) {
|
||||
throw new Error('Service not found. Please refresh the page and try again');
|
||||
}
|
||||
|
||||
throw new Error(errorData.detail || errorData.message || 'Failed to create ticket');
|
||||
throw new Error(errorData.detail || errorData.message || 'An unexpected error occurred');
|
||||
}
|
||||
|
||||
return await response.json();
|
||||
} catch (error) {
|
||||
console.error('Error creating ticket:', error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
@@ -239,7 +257,6 @@ export const checkTicketStatus = async (ticketNumber: string): Promise<SupportTi
|
||||
}
|
||||
return await response.json();
|
||||
} catch (error) {
|
||||
console.error('Error checking ticket status:', error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
@@ -268,7 +285,6 @@ export const addTicketMessage = async (
|
||||
if (!response.ok) throw new Error('Failed to add ticket message');
|
||||
return await response.json();
|
||||
} catch (error) {
|
||||
console.error('Error adding ticket message:', error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
@@ -284,7 +300,6 @@ export const getKnowledgeBaseCategories = async (): Promise<KnowledgeBaseCategor
|
||||
// Handle paginated response
|
||||
return data.results || data;
|
||||
} catch (error) {
|
||||
console.error('Error fetching knowledge base categories:', error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
@@ -303,7 +318,6 @@ export const getKnowledgeBaseArticles = async (search?: string): Promise<Knowled
|
||||
// Handle paginated response
|
||||
return data.results || data;
|
||||
} catch (error) {
|
||||
console.error('Error fetching knowledge base articles:', error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
@@ -319,7 +333,6 @@ export const getFeaturedArticles = async (): Promise<KnowledgeBaseArticle[]> =>
|
||||
// Handle both array and paginated responses
|
||||
return Array.isArray(data) ? data : (data.results || data);
|
||||
} catch (error) {
|
||||
console.error('Error fetching featured articles:', error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
@@ -333,7 +346,6 @@ export const getKnowledgeBaseArticle = async (slug: string): Promise<KnowledgeBa
|
||||
if (!response.ok) throw new Error('Failed to fetch knowledge base article');
|
||||
return await response.json();
|
||||
} catch (error) {
|
||||
console.error('Error fetching knowledge base article:', error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
@@ -349,7 +361,6 @@ export const getArticlesByCategory = async (categorySlug: string): Promise<Knowl
|
||||
// Handle paginated response
|
||||
return data.results || data;
|
||||
} catch (error) {
|
||||
console.error('Error fetching articles by category:', error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
@@ -369,7 +380,6 @@ export const markArticleHelpful = async (slug: string, helpful: boolean): Promis
|
||||
if (!response.ok) throw new Error('Failed to mark article helpful');
|
||||
return await response.json();
|
||||
} catch (error) {
|
||||
console.error('Error marking article helpful:', error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
@@ -385,7 +395,6 @@ export const getSupportSettings = async (): Promise<SupportSettings[]> => {
|
||||
// Handle paginated response
|
||||
return data.results || data;
|
||||
} catch (error) {
|
||||
console.error('Error fetching support settings:', error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
@@ -399,7 +408,6 @@ export const getSupportSetting = async (settingName: string): Promise<SupportSet
|
||||
if (!response.ok) throw new Error('Failed to fetch support setting');
|
||||
return await response.json();
|
||||
} catch (error) {
|
||||
console.error('Error fetching support setting:', error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user