Mhamdans17 commited on
Commit ·
6650d27
1
Parent(s): 9fc6937
Fix silent Cloudinary upload failure by checking resp.Error.Message
Browse files- services/cloudinary.go +6 -0
services/cloudinary.go
CHANGED
|
@@ -58,6 +58,12 @@ func UploadToCloudinary(fileHeader *multipart.FileHeader) (string, error) {
|
|
| 58 |
return "", fmt.Errorf("gagal upload ke Cloudinary: %v", err)
|
| 59 |
}
|
| 60 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
log.Printf("[CLOUDINARY] Upload sukses! URL: %s", resp.SecureURL)
|
| 62 |
return resp.SecureURL, nil
|
| 63 |
}
|
|
|
|
| 58 |
return "", fmt.Errorf("gagal upload ke Cloudinary: %v", err)
|
| 59 |
}
|
| 60 |
|
| 61 |
+
// Cloudinary SDK does not return an error when credentials or cloud name are invalid,
|
| 62 |
+
// instead it populates the Error field in the response. We must check it!
|
| 63 |
+
if resp.Error.Message != "" {
|
| 64 |
+
return "", fmt.Errorf("cloudinary error: %s", resp.Error.Message)
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
log.Printf("[CLOUDINARY] Upload sukses! URL: %s", resp.SecureURL)
|
| 68 |
return resp.SecureURL, nil
|
| 69 |
}
|