Introduce local fallback for book creation and improve error handling
- Added support for creating books locally when the cloud limit is reached. - Enhanced error handling in `AddNewBookForm` with `ApiError` and fallback logic for local book creation. - Implemented `BookTypeLimit` to manage type-specific book limits with visual indicators in `BookList`. - Refactored `TombstoneRecord` to standardize naming conventions for better API compatibility. - Updated `useSyncSeries` and `useSyncBooks` to handle empty tombstones gracefully. - Updated locales with new translations for fallback and error messaging.
This commit is contained in:
@@ -13,10 +13,20 @@ interface ApiRequestConfig {
|
||||
contentType?: ContentType;
|
||||
}
|
||||
|
||||
export class ApiError extends Error {
|
||||
statusCode: number;
|
||||
constructor(message: string, statusCode: number) {
|
||||
super(message);
|
||||
this.statusCode = statusCode;
|
||||
this.name = 'ApiError';
|
||||
}
|
||||
}
|
||||
|
||||
function handleApiError(error: unknown): never {
|
||||
if (axios.isAxiosError(error)) {
|
||||
const serverMessage: string = error.response?.data?.message || error.response?.data || error.message;
|
||||
throw new Error(serverMessage);
|
||||
const statusCode: number = error.response?.status ?? 500;
|
||||
throw new ApiError(serverMessage, statusCode);
|
||||
} else if (error instanceof Error) {
|
||||
throw new Error(error.message);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user