Skip to content

Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.

feat: improve error handling and user feedback in profile photo upload

fiber[bot]a592c83a3e5f
diff --git a/apps/erp/app/modules/account/ui/Profile/ProfilePhotoForm.tsx b/apps/erp/app/modules/account/ui/Profile/ProfilePhotoForm.tsx
index b52435329a..b6ad55c03a 100644
--- a/apps/erp/app/modules/account/ui/Profile/ProfilePhotoForm.tsx
+++ b/apps/erp/app/modules/account/ui/Profile/ProfilePhotoForm.tsx
@@ -34,7 +34,22 @@ const ProfilePhotoForm = ({ user }: ProfilePhotoFormProps) => {
);
if (!response.ok) {
- throw new Error("Failed to resize image");
+ let errorMessage = "Failed to resize image";
+ const contentType = response.headers.get("Content-Type");
+
+ // Try to parse error response if it's JSON
+ if (contentType?.includes("application/json")) {
+ try {
+ const errorData = await response.json();
+ if (errorData.error) {
+ errorMessage = errorData.error;
+ }
+ } catch {
+ // If JSON parsing fails, use generic message
+ }
+ }
+
+ throw new Error(errorMessage);
}
// Get content type from response to determine if it's JPG or PNG
@@ -50,7 +65,9 @@ const ProfilePhotoForm = ({ user }: ProfilePhotoFormProps) => {
avatarFile = resizedFile;
} catch (error) {
console.error(error);
- toast.error("Failed to resize image");
+ const errorMessage =
+ error instanceof Error ? error.message : "Failed to resize image";
+ toast.error(errorMessage);
return;
}
@@ -63,11 +80,17 @@ const ProfilePhotoForm = ({ user }: ProfilePhotoFormProps) => {
if (imageUpload.error) {
console.error(imageUpload.error);
- toast.error("Failed to upload image");
+ const errorMessage =
+ imageUpload.error.message || "Failed to upload image to storage";
+ toast.error(errorMessage);
+ return;
}
if (imageUpload.data?.path) {
+ toast.success("Photo uploaded successfully");
submitAvatarUrl(imageUpload.data.path);
+ } else {
+ toast.error("Upload completed but no file path returned");
}
}
};
@@ -79,9 +102,13 @@ const ProfilePhotoForm = ({ user }: ProfilePhotoFormProps) => {
.remove([user.avatarUrl]);
if (imageDelete.error) {
- toast.error("Failed to remove image");
+ const errorMessage =
+ imageDelete.error.message || "Failed to remove image";
+ toast.error(errorMessage);
+ return;
}
+ toast.success("Photo removed successfully");
submitAvatarUrl(null);
}
};
diff --git a/packages/database/supabase/functions/image-resizer/index.ts b/packages/database/supabase/functions/image-resizer/index.ts
index c033ff87a4..4e055f097d 100644
--- a/packages/database/supabase/functions/image-resizer/index.ts
+++ b/packages/database/supabase/functions/image-resizer/index.ts
@@ -57,7 +57,10 @@ serve(async (req: Request) => {
// For extremely large files, reject immediately
if (bytes.length > 10 * 1024 * 1024) {
// 10MB limit
- throw new Error("File too large, maximum size is 10MB");
+ const fileSizeMB = (bytes.length / (1024 * 1024)).toFixed(2);
+ throw new Error(
+ `File is ${fileSizeMB}MB, but maximum allowed size is 10MB`
+ );
}
// Enhanced JPG detection - check both file extension and MIME type
@@ -90,7 +93,7 @@ serve(async (req: Request) => {
dimensions.height > MAX_ALLOWED_DIMENSION
) {
throw new Error(
- `Image dimensions too large (${dimensions.width}x${dimensions.height}). Maximum allowed is ${MAX_ALLOWED_DIMENSION}x${MAX_ALLOWED_DIMENSION}`
+ `Image dimensions are ${dimensions.width}x${dimensions.height}, but maximum allowed is ${MAX_ALLOWED_DIMENSION}x${MAX_ALLOWED_DIMENSION}`
);
}