fix: prevent duplicate item creation with barcode conflict detection
Backend: - Added UNIQUE constraint check on barcode before item creation - Returns 409 Conflict with user-friendly message if duplicate exists - Prevents sqlite3.IntegrityError crashes Frontend: - Improved error handling for cloud sync failures - Detects 409 status code (duplicate barcode) - Shows specific error message to user - Gracefully falls back to local-only save Example error message: 'Item already exists. Item with barcode P66093-002 already exists (ID: 42). Update it instead or use a different barcode.'
This commit is contained in:
@@ -170,8 +170,15 @@ export default function Home() {
|
||||
await inventoryApi.createItem(currentUser.id, itemData);
|
||||
toast.success("Item saved to cloud catalog!");
|
||||
} catch (err: any) {
|
||||
console.error("Cloud sync failed:", err.message);
|
||||
toast.error("Item saved locally. Cloud sync failed.");
|
||||
const status = err.response?.status;
|
||||
const detail = err.response?.data?.detail || err.message;
|
||||
console.error("Cloud sync failed:", detail);
|
||||
|
||||
if (status === 409) {
|
||||
toast.error(`Item already exists. ${detail}`);
|
||||
} else {
|
||||
toast.error("Item saved locally. Cloud sync failed.");
|
||||
}
|
||||
}
|
||||
} else if (!isOnline) {
|
||||
toast.success("Item saved locally. Will sync when online.");
|
||||
|
||||
Reference in New Issue
Block a user