mirror of
https://github.com/taobataoma/meanTorrent.git
synced 2026-03-11 22:50:28 +01:00
fix(users): don't fail on missing old image on image upload (#1839)
Fixes scenarios where previously when old image file would be missing, uploading new image file over it would fail because unlinking previous file fails.
This commit is contained in:
@@ -111,7 +111,15 @@ exports.changeProfilePicture = function (req, res) {
|
||||
if (existingImageUrl !== User.schema.path('profileImageURL').defaultValue) {
|
||||
fs.unlink(existingImageUrl, function (unlinkError) {
|
||||
if (unlinkError) {
|
||||
console.log(unlinkError);
|
||||
|
||||
// If file didn't exist, no need to reject promise
|
||||
if (unlinkError.code === 'ENOENT') {
|
||||
console.log('Removing profile image failed because file did not exist.');
|
||||
return resolve();
|
||||
}
|
||||
|
||||
console.error(unlinkError);
|
||||
|
||||
reject({
|
||||
message: 'Error occurred while deleting old profile picture'
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user