Skip to content

Commit

Permalink
Catch errors when uploading white avatar (#3119)
Browse files Browse the repository at this point in the history
  • Loading branch information
askvortsov1 authored Oct 25, 2021
1 parent 5a1bf08 commit a661376
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions js/src/common/models/User.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,18 @@ Object.assign(User.prototype, {
const user = this;

image.onload = function () {
const colorThief = new ColorThief();
user.avatarColor = colorThief.getColor(this);
try {
const colorThief = new ColorThief();
user.avatarColor = colorThief.getColor(this);
} catch (e) {
// Completely white avatars throw errors due to a glitch in color thief
// See https://github.com/lokesh/color-thief/issues/40
if (e instanceof TypeError) {
user.avatarColor = [255, 255, 255];
} else {
throw e;
}
}
user.freshness = new Date();
m.redraw();
};
Expand Down

0 comments on commit a661376

Please sign in to comment.