Catch errors when uploading white avatar (#3119)

This commit is contained in:
Alexander Skvortsov 2021-10-25 17:34:39 -04:00 committed by GitHub
parent 5a1bf08d3f
commit a661376d16
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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();
};